Navicat远程连接MySQL

安装好MySQL后使用小窗口总是不方便的,然后下载了个Navicat远程连接MySQL,结果就出错了:Can't connect to MySQL server (10060)

Navicat远程连接MySQL_第1张图片

原因是MySQL的用户默认是没有远程访问权限的,因此当访问程序与数据库不是在同一服务器时,就无法访问了。解决办法有两种:

1.授权法:

赋予任何主机访问数据的权限

root@kerwin:/usr/local/mysql# bin/mysql -u root -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
mysql> FLUSH PRIVILEGES;

赋予特定IP主机访问数据的权限

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"XXX.XXX.XXX.XXX" IDENTIFIED BY "youpassword" WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

2.改表法

root@kerwin:/usr/local/mysql# bin/mysql -u root -p
mysql> use mysql;
mysql> update user set host = '%' where user = 'root'; 
mysql> select host, user from user; 
mysql> flush privileges;

测试

Navicat远程连接MySQL_第2张图片

重新连接成功

你可能感兴趣的:(MySQL)