Home  >  Article  >  Database  >  How to set up mysql to prohibit remote connections

How to set up mysql to prohibit remote connections

王林
王林Original
2020-09-27 15:24:015218browse

Mysql settings prohibit remote connections: 1. Log in to the database server and specify the mysql database; 2. Execute the [update user set host='localhost' where user='root';] statement; 3. Refresh permissions surface.

How to set up mysql to prohibit remote connections

Specific steps:

(Recommended tutorial: mysql video tutorial)

use mysql                #打开mysql数据库
 
#将host设置为localhost表示只能本地连接mysql
 
update user set host='localhost' where user='root';
 
flush privileges;        #刷新权限表,使配置生效

If we To enable remote connection, you can refer to the following method:

First log in:

mysql -u root -h localhost -p
use mysql   
#打开mysql数据库#将host设置为%表示任何ip都能连接mysql,当然您也可以将host指定为某个ip
update user set host='%' where user='root' and host='localhost';flush privileges;        
#刷新权限表,使配置生效

After completion, we can connect to our mysql remotely.

Related recommendations: php training

The above is the detailed content of How to set up mysql to prohibit remote connections. 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