Access Linux system database through remote tools

1 Principle

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-zXLKCEWj-1600391993784)(/img/bVbOXR8)]

Remote access to the database must pass through a firewall, and must have database access permissions, otherwise access is denied, then remote tools to access the database must consider two issues: how to enter the Linux system, whether the database allows access.

2 Test the connection

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-yrdlZjzu-1600391993789)(/img/bVbOXSw)]

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-RiXVbqc7-1600391993792)(/img/bVbOXSj)]

2 steps

2.1 Turn on the firewall

Firewall technology is a kind of organic combination of various software and hardware devices used for security management and screening to help computer networks build a relatively isolated protective barrier between their internal and external networks to protect user data and information security. technology.

2.1.1 Check the status of the firewall

命令:[root@localhost ~]# firewall-cmd --state
[External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-T3wGWMur-1600391993796)(/img/bVbOXS6)]

Check the ports opened by the firewall

命令:[root@localhost ~]# firewall-cmd --list-port

Check if a certain port is open

命令:[root@localhost ~]# firewall-cmd --query-port=3306/tcp
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-3GdBGUMa-1600391993800)(/img/bVbOXTT)]

Open a certain port firewall

命令:[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-rW1SbGRI-1600391993803)(/img/bVbOXT3)]

Close the firewall of a certain port

命令:[root@localhost ~]# firewall-cmd --zone=public --remove-port=3306/tcp --permanent
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-ok1zgvSq-1600391993805)(/img/bVbOXT5)]

2.1.2 Turn off the firewall

Command: [root@localhost ~]# systemctl stop firewalld.service
command: [root@localhost ~]# systemctl start firewalld.service Turn on the firewall
command: [root@localhost ~]# systemctl reload firewalld.service restart the firewall
command: [root @localhost ~]# [root@localhost ~]# firewall-cmd --reload restart firewall
command: [root@localhost ~]# [root@localhost ~]# firewall-cmd --state
[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-IVq1LIVR-1600391993807)(/img/bVbOXTp)]

2.2.3 Change the default startup mode of the firewall

The firewall will be activated when the Linux system is booted by default, so we can set the default boot mode to not boot up automatically.
Command: [root@localhost ~]# systemctl disable firewalld.service
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-IzHCTz7b-1600391993809)(/img/bVbOXTG)]

Command: [root@localhost ~]# systemctl enable firewalld.service starts up
[External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-hkFyYh9v-1600391993811)(/img/bVbOXTH)]

2.2 Turn on access permissions

2.2.1 Start the database

命令:[root@localhost src]# systemctl start mariadb
命令:[root@localhost src]# mysql -u root -p
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-GdJPZgg2-1600391993813)(/img/bVbOXUK)]

2.2.2 Open permissions

Change the localhost in the user table in the MySQL database to%
[External link image transfer failed. The origin site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-ejvsw9Rh-1600391993814)(/img/bVbOXU5)]

SQL:MariaDB [mysql]> update user set host="%" where host=“localhost”;
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-gkP6KTax-1600391993816)(/img/bVbOXVB)]

2.2.3 Refresh database permissions

Command: MariaDB [mysql]> flush privileges;
[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-4Z8Wcsto-1600391993818)(/img/bVbOX0O)]

2.3 Test connection

2.3.1 Open the remote connection tool and enter ip, user, password and port

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-Vgx9lus2-1600391993820)(/img/bVbOX1c)]

2.3.2 Test connection

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-hHNF75NT-1600391993822)(/img/bVbOX1t)]

2.3.3 View data successfully connected

[External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-ElnvJUb0-1600391993824)(/img/bVbOX1V)]

Guess you like

Origin blog.csdn.net/weixin_43388956/article/details/108658534