我有一个安装了 mysql 的 ubuntu 服务器,有一次我看到服务器上运行的 php 代码可以访问 mysql,但我无法远程访问 mysql,对于另一台服务器或 sequal pro。
$ mysql -u root -p
mysql> GRANT ALL on *.* TO 'thomas'@'%';
mysql> exit
$ mysql -u thomas -p
mysql> show grants;
+------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for thomas@localhost |
+------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'localhost' IDENTIFIED BY PASSWORD '[ENCRYPTEDPASSWORD]' WITH GRANT OPTION |
+------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> exit
$ mysql -u thomas -p -h [SERVERIP]
ERROR 1045 (28000): Access denied for user 'thomas'@'[SERVERNAME]' (using password: YES)
更新:
我没有进去并删除了所有创建的用户(有些没有密码),我在mysql.user
桌子旁使用drop user
命令。
CREATE USER 'thomas'@'localhost' IDENTIFIED BY '[PASSWORD]';
GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'localhost' IDENTIFIED BY '[PASSWORD]';
GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'[SERVERIP]' IDENTIFIED BY '[PASSWORD]';
GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'%' IDENTIFIED BY '[PASSWORD]';
表格现在看起来像这样:
+--------------+------------------+
| Host | User |
+--------------+------------------+
| localhost | root |
| localhost | phpmyadmin |
| 127.0.0.1 | root |
| ::1 | root |
| localhost | debian-sys-maint |
| localhost | thomas |
| [SERVERIP] | thomas |
| % | thomas |
+--------------+------------------+