How to install MySQL and enable remote connection on cloud server Ubuntu_Server_16.04.1

How to install MySQL and enable remote connection on cloud server 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 need to set the password for the MySQL root account.

Use the following command to check the MySQL socket status. If it is in the listening state, it means the installation is successful.

$ sudo netstat -tap | grep mysql

2. MySQL opens remote connection

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

Use the following command to modify:

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

Just press "i" to start vim insertion, then add a "#" sign before the statement to be commented out, then press "esc" to exit 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 in "/etc/mysql/my.cnf").

2. Create a user and authorize remote connections

First log in to MySQL, the command is as follows:

$mysql -u root -p

Then create a user and authorize him. The command format is as follows:

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=% means that the IP address of the connection is not restricted.

Refresh permissions to make the above configuration take effect immediately:

mysql>flush privileges;

Exit MySQL:

mysql>exit;

3. Test remote connection

1. Check the port number configured for MySQL

First enter MySQL, and then check the port number. The command is as follows:

$mysql -u root -p
mysql>show variables like 'port';

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

2. Check Ubuntu's firewall

Check the 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.

Check the status of port 3306

$netstat -an | grep 3306

3. Test MySQL remote connection

Open a command line window on your computer. The command format is:

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

According to the above configuration, the command to connect to the remote MySQL is:

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

Summarize

The above is the method that I introduced to you to install MySQL and enable remote connection on the cloud server Ubuntu_Server_16.04.1. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to modify mysql to allow remote connections
  • How to enable MySQL remote connection in Linux server
  • How to configure MySQL on Ubuntu 16.04 server and enable remote connection
  • How to enable remote connection (multiple backups) for MySQL database
  • mysql opens remote connection (mysql opens remote access)
  • How to enable remote connection to MySQL database
  • Detailed explanation of MySQL remote connection permission

<<:  JS Decorator Pattern and TypeScript Decorators

>>:  Example of how to implement keepalived+nginx high availability

Recommend

MySQL select, insert, update batch operation statement code examples

In projects, batch operation statements are often...

Two ways to introduce svg icons in Vue

How to introduce svg icons in Vue Method 1 of int...

Detailed explanation of common for loop in JavaScript statements

There are many loop statements in JavaScript, inc...

Detailed explanation of nginx's default_server definition and matching rules

The default_server directive of nginx can define ...

GZIP compression Tomcat and improve web performance process diagram

1. Introduction I recently worked on a project an...

Solve the problem of inconsistency between mysql time and system time in docker

Recently, when I installed MySQL in Docker, I fou...

Solution to Docker image downloading too slowly

Docker image download is stuck or too slow I sear...

Nginx uses Lua+Redis to dynamically block IP

1. Background In our daily website maintenance, w...

25 Ways and Tips to Increase Web Page Loading Speed

Introduction <br />Not everyone has access t...

Script example for starting and stopping spring boot projects in Linux

There are three ways to start a springboot projec...

React Class component life cycle and execution order

1. Two ways to define react components 1. Functio...

MySQL 8.0.13 installation and configuration method graphic tutorial

This article shares the installation and configur...

How to add custom system services to CentOS7 systemd

systemd: The service systemctl script of CentOS 7...