MYSQL-Configure mysql server to allow clients to connect remotely

1. Check the users of the mysql server, you can find that the host is all localhost, that is , only local login is allowed.
Insert picture description here
2. Add the root user (administrator user) and abong user (ordinary user), and the corresponding host name %refers to allowing login to the mysql database on the client on any host . The host name can also be a certain network segment.

mysql> use mysql;
Database changed
mysql> grant all on *.* to 'root'@'%' identified by 'Abong123.';    -- 创建root用户
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant select on *.* to 'abong'@'%' identified by 'Abong123.';    -- 创建abong用户
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user;     -- 可以看到root用户和abong用户所对应的host为%,这表示允许在任何IP访问数据库。
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | abong         |
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
5 rows in set (0.00 sec)

3. Open the 3306port number of the firewall

[root@server ~]# firewall-cmd --permanent --zone=public --add-port=3306/tcp
success
[root@server ~]# firewall-cmd --reload 
success

4. Use the Navicat client tool to log in to the database. You can see that both the root user and the abong user can connect to the mysql database on the Navicat client.
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_36522099/article/details/108608426