MySql 局域网连接设置
# MySql 局域网连接设置1. **用户权限**
2. **数据库权限**
3. **防火墙**
## 权限
### 用户权限
- **了解通配符**
1._:表示任意单个字符
2. %:表示任意长度的任意字符
```mysql
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| gin| % | *5F0280C046A65B831FBA554AF2FF25D2BEDB4FA7 |
+------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
```
**host** 字段代表访问的 **IP** 地址限制 **%** 代表所有IP段, 比如 **192.%.%.%** 只有 192开头的IP才能访问
- **删除用户**
```mysql
mysql> drop user gin@'%';
Query OK, 0 rows affected (0.03 sec)
```
- **创建用户**
```mysql
mysql> create user gin@'%' identified by 'gin';
Query OK, 0 rows affected (0.02 sec)
```
**identified by "密码"**
### 数据库权限
- **查询用户数据库权限**
1. **语法**
```mysql
show grants for 用户名;
```
如查看 root@localhost 用户权限信息
```mysql
show grants for root@localhost;
```
```mysql
mysql> show grants for gin@'%';
+----------------------------------------------------------------------------------------------------+
| Grants for gin@% |
+----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'gin'@'%' IDENTIFIED BY PASSWORD '*5F0280C046A65B831FBA554AF2FF25D2BEDB4FA7' |
| GRANT ALL PRIVILEGES ON `userinfo`.* TO 'gin'@'%' |
+----------------------------------------------------------------------------------------------------+
2 rows in set (0.02 sec)
```
**`ALL` 表示所有权限 `userinfo` 数据库名,`.*` 表示它下面的所有表**
- **删除权限**
```mysql
revoke "权限" on 数据库.表 from 用户@host;
```
```mysql
mysql> revoke all on userinfo.* from gin@'%';
Query OK, 0 rows affected (0.00 sec)
```
- **创建权限**
```mysql
GRANT ALL ON db.tbl TO 'username'@'host' IDENTIFIED BY 'password';
```
```mysql
mysql> grant all on userinfo.* to gin@'%';
Query OK, 0 rows affected (0.00 sec)
```
## 防火墙
- **设置防火墙允许访问端口3306**
1. 打开控制面板->windows防火墙->高级设置,点击(左边)入站规则 (右边)新进规则
2. 点击端口,点击下一步
3. 在特定端口中输入**Mysql**端口号 **3306**,点击下一步
4. 默认选中允许连接,点击下一步
5. 默认选中全部网络,点击下一步
6. 输入名称(如Mysql)与描述(...),点击完成 嗯,这个顶一下,感谢发享 学到了,嘻嘻嘻 {:1_921:} 还是很详细的:lol:lol:lol
页:
[1]