クライアントが Mysql に接続し、エラーを報告する

エラーメッセージ

Mysql は Centos システムにインストールされており、Naticat を使用して Mysql に接続するとエラーが報告されます。情報は次のとおりです。

ホスト「192.168.237.1」はこの MariaDB サーバーへの接続を許可されていません 

解決

1.Mysqlを入力します

mysql -u root -p

パスワードを入力する

[root@localhost src]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 360
Server version: 10.2.43-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

2.mysqlデータベースに入ります

mysqlを使用します。

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

3. ユーザーのホストを表示する

ユーザーからホスト、ユーザー、パスワードを選択します。

MariaDB [mysql]> select host, user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *D06A34E97174580E449FBB7AAF0481C1744FCB |
| 127.0.0.1 | root | *D06A34E97174580E449FBB7AAF0481C1744FCB |
| ::1       | root | *D06A34E97174580E449FBB7AAF0481C1744FCB |
| %         | root | *2470C0C06DEE42F618BB99005ADCA2EC9D1E19 |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)

このとき、% というホストに対応するパスワードは他の 3 つと異なり、% はどのホストからでも Mysql データベースへの接続を許可することを意味することがわかります。

4. ホストが % であるレコードを削除します。

ホスト = '%' のユーザーから削除します。

MariaDB [mysql]> delete from user where host = '%';
Query OK, 1 row affected (0.00 sec)

5. 認証によりどのホストからでも接続が可能になります

GRANT オプションを使用して、*.* のすべての権限を' xxx 'で識別された ' root '@'%'に付与します。

  • 注: xxx は root ユーザーのパスワードです。他のユーザーを変更する場合は、root を他のユーザーに変更できます。
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxx' WITH GRANT OPTION; 
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

6. 認証を更新して有効にします。

フラッシュ特権;

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

上記の手順5と6を1つの手順にまとめて、ホストを%に変更し、パスワードを他の3つのパスワードに変更することもできるような気がしますが、まだ試していません。次回試してみます。

ユーザーを更新するには、パスワード = 'xxxx'、ホスト = '%'; を設定します。 

おすすめ

転載: blog.csdn.net/ling1998/article/details/130229809