-- 根据MySql版本的不同,需要做不同的操作处理
8.0.13之前的版本随便都可以在网上查到。
针对8.0.13之后的版本 -(都在服务器电脑操作)
1、打开mysql控制台,进入mysql
use mysql;
2、查询mysql当前的版本
select @@version;
3、创建用户(局域网客户端用户)
create user '自定义用户名'@'客户端电脑IP' identified by '自定义密码';
测试用例:
create user 'root'@'192.168.100.134' identified by '123456';
4、赋予权限(局域网客户端用户)
grant all privileges on *.* to '自定义用户名'@'客户端电脑IP';
测试用例:
grant all privileges on *.* to 'root'@ '192.168.100.134';
5、刷新,若不刷新则不能使用
flush privileges;
6、接下来可以在客户端的数据库上连接数据库。如果出现连接失败,mysql8之后的版本加密规则改变的问题。具体的解决方案如下:
mysql8之前的版本中加密规则是mysql_native_password,而在mysql8之后的版本中,加密规则是caching_sha2_password
具体修改操作如下:
(1)mysql中先更改加密方式
alter user '自定义用户名'@'客户端电脑IP' identified by '自定义密码' password expire never;
测试用例:
alter user 'root'@'192.168.100.134' identified by 'password' password expire never;
(2)修改密码,由于加密规则更改,所以需要重新设置密码
alter user '自定义用户名'@'客户端电脑IP' identified with mysql_native_password by '自定义新密码' ;
测试用例:
alter user 'root'@'192.168.100.134' identified with mysql_native_password by '123456789 ;