Linux 配置MySQL远程登陆方式,方便MySQL客户端访问
一、配置前查看MySQL数据库状态。
[root@Demo-Environment appuser]# systemctl status mysqld.service

二、配置MySQL指定root用户远程访问MySQL数据库(一般不建议直接运行root哈)
1.使用root登录MySQL数据库(终端屏幕)。
[root@Demo-Environment mysql]# mysql -u root -p

2.查看当前用户信息表,Host默认都为localhost,即不允许远程登录。
mysql> SELECT User,Host FROM user;

3.设置root远程登录,mysql8.0以后采用新的语法。
mysql> create user 'root'@'%' identified by 'Myabc321@Sql';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql>

4.刷新用户权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>

- 验证root用户远程登录
1.打开本地Navicat for MySQL软件。

2.新建连接

3.点击确定按钮后,可正常远程访问MySQL数据库。

验证过程中,无法连接到远程数据库,不要慌,想想出现这种报错的原因?

----因为我的环境部署在华为云服务器上,安全组未开通MySQL的服务端口3306,其他云或Linux环境请检查是否放通MySQL服务端口,否则会报无法连接哦。
附:华为云新增MySQL服务端口安全组配置
1.查看当前安全组配置

2.新增MySQL服务3306端口

Linux学习是个不断总结和实践的过程,涉及很多开源软件的安装和使用,如MySQL,Nginx、Redis等