Ubuntu Server 16.04 Install MySQL and Set Up Remote Access

Install MySQL on Ubuntu  Server 16.04

1. Use root account

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

If there is a problem in the middle, execute the following apt-get update

2. After the installation of the above three software packages is complete, use the following command to check whether the installation is successful:

sudo netstat -tap | grep mysql

The query result is shown in the following figure, indicating that the installation is successful.

root@ubuntu:~# netstat -tap | grep mysql
tcp6      0      0 [::]:mysql              [::]:*                  LISTEN      7510/mysqld    
root@ubuntu:~#

Second, set up mysql remote access

1. Edit the mysql configuration file and comment out bind-address = 127.0.0.1

vi /etc/mysql/my.cnf

2. Use root to enter the mysql command line and execute the following two commands. In the example, the root account password of mysql is: root

root@ubuntu:~# mysql -uroot -proot

mysql>grant all on *.* to root@'%' identified by 'root' with grand option;

 *.*: The first * represents the database name; the second * represents the table name. This means that all tables in all databases are authorized to the user. root: Grant the root account. "%": Indicates that the authorized user IP can be specified, which means that any IP address can access the MySQL database. "password": The password corresponding to the assigned account, where the password is replaced by your mysql root account password.

mysql>flush privileges;

Refresh the permission information, that is, let the settings we make take effect immediately.

3. Restart mysql

/etc/init.d/mysql restart

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325369639&siteId=291194637