设置mysql允许外部连接访问
1.错误信息::
SQL Error (1130): Host ‘192.168.1.88’ is not allowed to connect to this MySQL server 说明所连接的用户帐号没有远程连接的权限,只能在本机(localhost)登录。
2.原因:
mysql默认情况下,只允许localhost连接,如果需要外部IP连接到mysql,需要向mysql数据库里的“user”表里添加相关授权。
3.具体步骤:
3.1.修改user表访问权限
更改 mysql 数据库里的 user表里的 host项 把localhost改称%
3.1.1.sql修改
use mysql;
select * from user;
drop user 'root'@'%' ;
create user 'root'@'%' identified by '密码' ;
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
※ grant语法: grant 权限名(所有的权限用all) on 库名(*全部).表名(*全部) to ‘要授权的用户名’@’%’(%表示所有的IP,可以只些一个IP) identified by “密码”;
3.1.2.或者命令修改
登录数据库
mysql -u root -p
输入密码
mysql> use mysql;
查询host
mysql> select user,host from user;
4.创建host
如果没有"%"这个host值,就执行下面这两句:
mysql> update user set host='%' where user='root';
mysql> flush privileges;
5.授权用户
任意主机以用户root和密码mypwd连接到mysql服务器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
mysql> flush privileges;
一般修改到这里就大功告成了🙂
3.2.修改MySQL数据库加密方式
如果没有成功,可能发生了和我电脑一样的bug:
错误:2059 - authentication plugin ‘caching_sha2_password’
出现这个错误的原因是因为MySQL数据库使用的加密方式是:caching_sha2_password;
可以使用如下命令查看一下加密信息:
show variables like 'default_authentication_plugin';
/
show variables like 'default_authentication%';
在Navicat不支持MySQL的这种用户登录账户加密方式,所以下面我们要修改root账户的加密方式为【mysql_native_password】:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';/
alter user 'root'@'%' identified with mysql_native_password by '密码';
查看修改后状态:
select plugin from mysql.user ;
再次测试链接,成功!!!!!