Article directory
Problem Description
-
Step one: Check the network configuration and see if you can ping the client. (jump over)
-
Step 2: MySQL on the client machine is not started:
systemctl status mysqld
[root@localhost mysql]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 四 2022-10-13 06:01:00 UTC; 41min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 10500 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 10479 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 10503 (mysqld) Tasks: 28 CGroup: /system.slice/mysqld.service └─10503 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 10月 13 06:01:00 localhost.localdomain systemd[1]: Stopped MySQL Server. 10月 13 06:01:00 localhost.localdomain systemd[1]: Starting MySQL Server... 10月 13 06:01:00 localhost.localdomain systemd[1]: Started MySQL Server.
-
Step 3: Port 3306 on the firewall is not open, check:
ss -lnt
[root@localhost mysql]# ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 128 *:6000 *:* LISTEN 0 5 192.168.122.1:53 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 80 :::3306 :::* LISTEN 0 128 :::111 :::* LISTEN 0 128 :::6000 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6010 :::*
-
Port 3306 is open, but port 3306 is not monitored! (This is my problem), so first add the port that needs to be monitored:
[root@localhost mysql]# firewall-cmd --permanent --zone=public --add-port=3306/tcp Warning: ALREADY_ENABLED: 3306:tcp success [root@localhost mysql]# firewall-cmd --permanent --zone=public --add-port=3306/tcp Warning: ALREADY_ENABLED: 3306:tcp success
-
After adding port 3306, you can test it. If it shows that the connection is not allowed, then open mysql, log in with root, enter the mysql database, query the mysql.user table, you can see that HOST is localhost, which means that you can only log in to mysql locally. ,
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select User,HOST from mysql.user; +---------------+-----------+ | User | HOST | +---------------+-----------+ | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 3 rows in set (0.00 sec)
-
Increase remote access permissions. The % sign means that any IP is allowed to access the database, and refresh:
flush privileges;
, then restart the mysql database, and then you can log in normally.mysql> grant all privileges on *.* to root@"%" identified by "1234566"; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select User,HOST from mysql.user; +---------------+-----------+ | User | HOST | +---------------+-----------+ | root | % | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 4 rows in set (0.00 sec) mysql> systemctl restart mysqld