mysql - 远程访问数据库

标签 mysql ubuntu privileges

我有一个安装了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           | 
+--------------+------------------+

最佳答案

嗯,你已经

GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'localhost'

但您不在localhost上。您可能想尝试一下

GRANT ALL PRIVILEGES ON *.* TO 'thomas'@'%'

当然,如果您愿意,您必须添加IDENTIFIED BY 'password'

关于mysql - 远程访问数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11232219/

相关文章:

PostgreSQL:显示具体用户的所有权限

mysql - 复杂的mysql注入(inject)

mysql - 合并表而不是相交

apache - apache2 中的密码文件是什么?

c - 连续监听端口并将数据转储到文本文件

具有权限结构的PHP网站

mysql - 尽管注释掉了安全文件 priv 部分,但仍出现“错误 1290 (HY000)”

php - 在 php 中用表而不是行填充我的下拉列表?

python - Ansible 忽略 ansible_python_interpreter 作为命令行参数

sql - 仅使用 SELECT 用户执行不受信任的 SQL