How to install MySQL and enable remote connection on the ECS Ubuntu_Server_16.04.1,
1. Install MySQL:
Use the following three commands to install the corresponding software:
$sudo apt-get install mysql-server$sudo apt-get install mysql-client$sudo apt-get install libmysqlclient-dev
When executing the first command, you must set the password of the root account of MySQL.
Run the following command to check the scoket status of MySQL. If the instance is in the listen status, the installation is successful.
$sudo netstat -tap | grep mysql
2. enable remote connection for MySQL
1. Modify the mysql configuration file and setbind-address = 127.0.0.1
Comment, open all connections
Use the following command to modify:
$sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
Press "I" to enable vim insertion, add "#" before the statement to be annotated, press "esc" to exit the vim insertion status, and then press ": wq "Save and exit. (The configuration file of mysql5.7 + is as above, and earlier versions are in "/etc/mysql/my. cnf ").
2. Create a user and authorize remote connection
Log on to MySQL with the following command:
$mysql -u root -p
Create a user and authorize the user. The command format is as follows:
mysql>GRANT privileges ON databasename.tablename TO 'username'@'host' IDENTIFIED BY 'password' WITH GRANT OPTION;
For example, my own configuration command:
mysql>grant all privileges on *.* to 'ubuntu'@'%' identified by '123456' with grant option;
Note: host = % indicates that the connected IP address is not restricted.
Refresh the permission 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 for 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. to modify the port number, enter the configuration file to modify the port information (see 2.1 for operations). The following uses port = 3306 as an example.
2. view the Ubuntu Firewall
View the Firewall Status:
$sudo ufw status
Enable 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 the command line window on your computer. Command Format:
$mysql -h ipaddress -P port -u ubuntu -ppassword
Run the following command to connect to a remote MySQL instance:
$mysql -h 193.112.19.56 -P 3306 -u ubuntu -p123456
Summary
The above section describes how to install MySQL and enable remote connection on ECS Ubuntu_Server_16.04.1. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!