Set up Mysql to allow external network access to the detailed process

Recently deployed mysql5.6, found that the default mysql only allows local services, if you want to do some configuration, record as follows.


1. Set up MySQL service to allow external network access

Modify the configuration file of mysql , some are my.ini (windows), some are my.cnf (linux),

add in config file

[mysqld]

port=3306

bind-address=0.0.0.0

Then restart the mysql service and execute service mysql restart.

2. Set up mysql users to support external network access

You need to log in to mysql with root privileges, update the mysql.user table, and set the Host field of the specified user to %. The default is generally 127.0.0.1 or localhost.

1. Log in to the database
mysql -u root -p

Enter password
mysql> use mysql;


2.查询host
mysql> select user,host from user;


3.
If there is no host value of "%" when creating a host, execute the following two sentences:
mysql> update user set host='%' where user='root';
mysql> flush privileges;


4. Authorized user
(1) Any host connects to the mysql server with user root and password mypwd
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
mysql> flush privileges;

(2) The host whose IP is 192.168.133.128 connects to the mysql server with user myuser and password mypwd
mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.133.128' IDENTIFIED BY 'mypwd' WITH GRANT OPTION; 
mysql> flush privileges;


【host field description】
% Allow login from any ip  
xxxx Allow access from specified ip


Guess you like

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