---
title: "MySQL Remote Connection: % Privilege"
url: https://www.geekcorelab.cn/en-US/post/permission-for-mysql-remote-connection
updated: 2026-11-04T03:54:55.341356Z
author: "hhjmk"
summary: "文章主要介绍了如何解决远程电脑管理数据库连接失败的问题。首先需要开启MySQL的3306端口，通过编辑iptables防火墙配置文件并重启防火墙实现。接着使用mysql命令连接到MySQL，进入mysql数据库表，查看用户表并更新root用户的Host属性为%，或指定IP地址，最后刷新权限。完成这些步骤后即可成功远程连接数据库。"
---

# MySQL Remote Connection: % Privilege

We often encounter this problem when managing databases from a remote computer  
![Connection failed](/uploads/import-placeholder/385)
  
So this article will help you solve this problem

> The test server uses CentOS7.5-MySQL5.5  
> You need to open the `MySQL` port first; otherwise, it will not connect even after configuration  
> If you are using an `iptables` firewall, you can open `3306` with the following operations  
> `vi /etc/sysconfig/iptables #编辑防火墙配置文件`  
> Add a line at the very bottom  
> `-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT`  
> `:wq! #保存退出`  
> Then you need to restart the firewall  
> `systemctl restart iptables.service #重启防火墙使配置生效`  
> `systemctl enable iptables.service #设置防火墙开机启动`

**The operation is very simple, just 5 steps, as follows:**

First, connect to MySQL

`mysql -uroot -p` or `/usr/local/mysql/bin/mysql -u root -p`

Then, when `Enter password:` appears, enter your MySQL `root` password

**If the following image appears, it means MySQL connected successfully**

![Connect to MySQL](/uploads/import-placeholder/273)
Enter the `mysql` table

```
use mysql;

```

![Enter the mysql table](/uploads/import-placeholder/418)
View the user table

```
SELECT `Host`,`User` FROM user;

```

![View users](/uploads/import-placeholder/413)
Update the permissions of the `root` user

```
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
```

% can be changed to a specified IP  
![Update root](/uploads/import-placeholder/159)

Force refresh permissions

```
flush privileges;

```

![Update permissions](/uploads/import-placeholder/320)
After completing the above steps, you can connect to the database remotely

![Success](/uploads/import-placeholder/430)
