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> create user gin@'%' identified by 'gin';
Query OK, 0 rows affected (0.02 sec)
identified by "密码"
数据库权限
- 语法
show grants for 用户名;
如查看 root@localhost 用户权限信息
show grants for root@localhost;
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 数据库名, `.` 表示它下面的所有表**
-
删除权限
revoke "权限" on 数据库.表 from 用户@host;
mysql> revoke all on userinfo.* from gin@'%';
Query OK, 0 rows affected (0.00 sec)
-
创建权限
GRANT ALL [PRIVILEGES] ON db.tbl TO 'username'@'host' IDENTIFIED BY 'password';
mysql> grant all on userinfo.* to gin@'%';
Query OK, 0 rows affected (0.00 sec)
防火墙
- 设置防火墙允许访问端口3306
- 打开控制面板->windows防火墙->高级设置,点击(左边)入站规则 (右边)新进规则
- 点击端口,点击下一步
- 在特定端口中输入Mysql端口号 3306,点击下一步
- 默认选中允许连接,点击下一步
- 默认选中全部网络,点击下一步
- 输入名称(如Mysql)与描述(...),点击完成
|