Home  >  Article  >  Database  >  How to allow mysql to be accessed from the external network

How to allow mysql to be accessed from the external network

coldplay.xixi
coldplay.xixiOriginal
2020-10-12 13:42:2116683browse

How to make mysql accessible from the external network: first modify the mysql configuration file and add relevant code to the configuration file; then restart the mysql service and execute [service mysql restart]; finally create a host and authorize the user That’s it.

How to allow mysql to be accessed from the external network

##Related learning recommendations: mysql video tutorial

How to allow mysql to be accessed by the external network:

1. Set the MySQL service to allow external network access

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

Add

[mysqld]
port=3306
bind-address=0.0.0.0

in the configuration file and then restart the mysql service and execute service mysql restart.

2. Set the mysql user to support external network access

You need to log in to mysql with root permissions, 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. Query host

mysql> select user,host from user;

3. Create host

If not" %"For this host value, 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 with IP 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;

The above is the detailed content of How to allow mysql to be accessed from the external network. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn