Remote connection to MySQL

The new installation of MySQL and can not be remotely connected to the server, you need the following steps to resolve

0. View the port open case

  1. Ali cloud the 3306 port security group is set to 0.0.0.0/0, open to all
  2. Confirm that you can connect through port scanning tool: port scanning tool
  3. Login server, netstat -an | grep 3306see MySQL's operation and monitor the situation, we found that 3306 port is listening only on the local
root@iZbp12kno11kc9e34bktfaZ:/var/log/mysql# netstat -an | grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN 

1. open port and restart

  1. MySql modify the configuration file, open port listening
vim /etc/mysql/mysql.conf.d/mysqld.cnf 
...
# bind-address          = 127.0.0.1 //注释掉这行
...
  1. Restart MySQl
service mysql restart
  1. View the port status monitor
netstat -an | grep 3306
tcp6       0      0 :::3306         :::*             ISTEN     

Now has access to the external port 3306, but in order to connect MySQL, you need to configure a remote connection permissions have an account "local connection is the default root privileges."

Configuring the remote user is connected

// 创建用户
mysql> create user arong;
Query OK, 0 rows affected (0.00 sec)
// 为用户配置全部权限
mysql> grant all privileges on *.* to arong@'%' identified by '123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
// 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

After completion of the above can be used to connect remote users of the MySQL server.

Published 309 original articles · won praise 205 · Views 300,000 +

Guess you like

Origin blog.csdn.net/pbrlovejava/article/details/103861551