开放root远程连接数据库的权限(Linux系统)
环境:centos7,关闭防火墙(没关要开放数据库的端口)
一、进入数据库,查看权限表信息
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [mysql]> select Host,User from user;
+-----------+------+
| Host | User |
+-----------+------+
| 127.0.0.1 | root |
| ::1 | root |
| chensy | root |
| localhost | root |
+-----------+------+
4 rows in set (0.00 sec)
二、给root用户权限
MariaDB [mysql]> grant all privileges on *.* to 'root'@'%' identified by '数据库密码' Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> select Host,User from user;
+-----------+------+
| Host | User |
+-----------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| chensy | root |
| localhost | root |
+-----------+------+
5 rows in set (0.00 sec)
三、刷新数据库权限
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
四、重启数据库
[root@chensy ~]# systemctl restart mariadb
五、远程连接数据库