mysql 开启远程连接
2019-10-24 本文已影响0人
码农工号9527
- 进入mysql控制台
mysql -uroot -p
- 切换数据库
use mysql;
可以看看用户表的信息:select host,user from user;
mysql> use mysql;
Database changed
mysql> select host,user from user;
+-----------+------+
| host | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | root |
+-----------+------+
3 rows in set (0.00 sec)
- 创建用户
CREATE USER 'your_user_name'@'localhost' IDENTIFIED BY 'pwd';
localhost:你的主机名
pwd:你的密码
- 给用户授权
grant all privileges on *.* to 'your_user_name'@'localhost';
all:给用户添加那些权限,有select,delete等,如果有多个可用逗号(,)分隔,全部权限使用all
第一个 * :代表数据库名,全部数据可用 * 代替
第二个 * :代表数据库下的表名,数据库下的全部表可使用 * 代替
'your_user_name'@'localhost':代表用户名和可访问的主机
- 刷新权限
flush privileges;
测试本地登录,连接成功
- 开启远访问
mysql> update user set host="%" where user="lpb";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)