我有一个安装了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 |
+--------------+------------------+
答案 0 :(得分:2)
嗯,你有
GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'localhost'
但你不在localhost
。您可能想尝试
GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'%'
当然,如果你愿意,你必须添加IDENTIFIED BY 'password'