---
title: "mysql设置允许外部访问"
author: "clark1231"
date: "2012-03-27T09:01:01Z"
tags: ["MySQL"]
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2012-03-27T09:01:01Z"
id: 1464677
url: "https://caok1231.iteye.com/blog/1464677"
---

配置外部访问帐号密码

本地登录mysql

```
mysql -uroot -p
```

 

执行

```
grant all on *.* to rails@'client_ip' identified by 'password' with grant option;
```

 

例子：所有局域网客户端都可访问

```
grant all on *.* to root@'192.168.0.%' identified by 'root' with grant option;
```

 

例子：为boyu数据库设置用户boyu

```
grant all on boyu.* to boyu@'192.168.0.%' identified by 'p4ssword';
```

 app\_server\_id为APP应用服务器的IP

 

设置mysql外部能访问

/etc/mysql/my.cnf

注释到下面这行

```
bind-address = 127.0.0.1
```

 

重启mysql-server

```
sudo service mysql restart
```