mysql 远程连接 mySql数据库常见问题

Mysql 默认情况下禁止 root 用户远程连接,如果要使用 root 用户远程连接,确保以下设置:

1、/etc/mysql/ 目录下找到mysql 配置文件修改

1
2
3
4

修改为

``` bind-address = 0.0.0.0

2、修改 mysql 表中 root 用户的 host 字段为 ‘%’

1
2
3
4
5
6
mysql -u root -p`
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host' from user where user='root';

运行以上 SQL 语句后,重启 mysql 服务,尝试重新连接。