参考于:https://blog.csdn.net/piaocoder/article/details/53704126?utm_source=copy
1.添加新用户
允许本地 IP 访问 localhost, 127.0.0.1
create user 'liu'@'localhost' identified by '123456';
2.允许外网 IP 访问
create user 'liu'@'%' identified by '123456';
3.刷新授权
flush privileges;
4.为用户创建数据库
create database liu DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
5.为新用户分配权限
授予用户通过外网IP对于该数据库的全部权限
grant all privileges on `testdb`.* to 'liu'@'%' identified by '123456';
6.授予用户在本地服务器对该数据库的全部权限
grant all privileges on `testdb`.* to 'liu'@'localhost' identified by '123456';
7.刷新权限
flush privileges;
8.退出 root 重新登录
exit
9.用新帐号 liu 重新登录,由于使用的是 % 任意IP连接,所以需要指定外部访问IP
mysql -u liu -h xx.xx.xx.xx -p
本地Navicat远程连接该linux服务器上的mysql
可参见:https://blog.csdn.net/weixin_39516640/article/details/115556322?spm=1001.2014.3001.5501