Get the App
SLTechnology News&Howtos  ›  Database  › 

How to install MySQL on CVM Ubuntu_Server_16.04.1 and open a remote connection

Shulou Source: shulou.com Published: 2022-06-01 03:36:10 10月05日 Update

1. Install MySQL:

Use the following three commands to install the appropriate software:

$sudo apt-get install mysql-server$sudo apt-get install mysql-client$sudo apt-get install libmysqlclient-dev

In the process of executing the first command, you need to set the password for MySQL's root account.

Use the following command to check the scoket status of MySQL. If you are in the listen state, the installation is successful.

$sudo netstat-tap | grep mysql

2. MySQL opens a remote connection

1. Modify the mysql configuration file, comment bind-address = 127.0.0.1, and open all connections

Modify it with the following command:

$sudo vim / etc/mysql/mysql.conf.d/mysqld.cnf

First press "I" to turn on vim insertion, then add a "#" sign before the statement to be commented, press "esc" to exit the vim insertion state, and then press ": wq" to save and exit. (the configuration file for mysql5.7+ is as above, and the previous version is "/ etc/mysql/my.cnf").

two。 Create a user and authorize to allow remote connections

Log in to MySQL first with the following command:

$mysql-u root-p

Then create a user and authorize it in the following format:

Mysql > GRANT privileges ON databasename.tablename TO 'username'@'host' IDENTIFIED BY' password' WITH GRANT OPTION

Such as my own configuration command:

Mysql > grant all privileges on *. * to 'ubuntu'@'%' identified by' 123456 'with grant option

Note: host=% indicates that the IP address of the connection is not restricted.

Refresh permissions so that the above configuration takes effect immediately:

Mysql > flush privileges

Exit MySQL:

Mysql > exit

3. Test remote connection

1. View the port number configured by MySQL

Enter MySQL first, and then check the port number. The command is as follows:

$mysql-u root-pmysql > show variables like 'port'

The default port number of MySQL is 3306. If you need to modify the port number, you can go to the configuration file to modify the port information (see 3306 for operation). Take port=3306 as an example.

two。 View Ubuntu's firewall

View firewall status:

$sudo ufw status

Open the firewall and open port 3306

$sudo ufw enable$sudo ufw default deny$sudo ufw allow 3306

Remember to open other necessary ports, such as ssh port 22.

View the status of port 3306

$netstat-an | grep 3306

3. Test MySQL remote connection

Open a command line window on your computer in the command format:

$mysql-h ipaddress-P port-u ubuntu-ppassword

As configured above, the command to connect to the remote MySQL is:

$mysql-h 193.112.19.56-P 3306-u ubuntu-p123456

Summary

The above is the method of installing MySQL and opening remote connection on CVM Ubuntu_Server_16.04.1 introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

Tags: Commands configuration status ports slogans files firewalls fire prevention formats comments users tests methods servers services necessary success above information address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Linux Microsoft Shulou Tech Info MariaDB