# 允许ROOT用户远程访问MySQL

测试环境（对安全性要求较低）需要设置允许ROOT用户远程访问数据库，方便使用图形管理工具。

> 默认MySQL禁止`root`远程访问

使用以下SQL设置允许：

```sql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
```

> 已验证，在 `GRANT` 命令中，需要在字符串 `root` `%` 和 `password` 的前后加上单引号，否则会报错。

并且在配置`my.cnf`文件中设置

```
bind-address = 127.0.0.1
```

注释掉这行：

```
#bind-address = 127.0.0.1
```

> 如果`my.cnf`中有限制IP绑定的设置，修改后需要重启MySQL服务

## 参考

* [How to allow remote connection to mysql](https://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/database/mysql/install_and_upgrade/allow_root_remote_connection_to_mysql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
