远程连接mysql

533#e6282aab

方法一:dos命令修改法,快捷键win+r打开运行,输入cmd打开命令行程序,输入mysql -u root -p连接mysql,如果出现mysql不是什么什么命令,将mysql的bin目录配置到环境变量中的path中即可...

方法一:dos 命令修改法

快捷键 win+r 打开运行,输入 cmd 打开命令行程序,输入代码连接 mysql

sql 复制代码
mysql -u root -p

如果出现 mysql 不是什么什么命令,将 mysql 的 bin 目录配置到环境变量中的 path 中即可
接着输入 root 用户密码,连接成功后会提示如下信息,每个版本可能不一样

doc 复制代码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

接着输入 use mysql 修改当前数据库为 mysql

sql 复制代码
use mysql;

接着可以试试查询 mysql 数据库里的 user 表信息

doc 复制代码
select host,user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| localhost | mysql.sys |
| localhost | root      |
+-----------+-----------+
2 rows in set (0.00 sec)

对应用户的 host 值为 localhost,代表该用户只能在本地连接数据库,下面我们输入 sql 语句将 root 赋予远程连接的权限:

sql 复制代码
// root为远程连接用户名,123456为密码,自行设置
grant all privileges  on *.* to root@'%' identified by "123456";

GRANT ALL PRIVILEGES ON *.* TO developer@'%' IDENTIFIED BY '123456';

再执行查询,会发现多了一条信息

doc 复制代码
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
| localhost | root      |
+-----------+-----------+
3 rows in set (0.00 sec)

代表已经授权给 root 在其他机器连接了,这时就可以在其他机器上使用 root 连接本机的 mysql 数据库了。

方法二:直接修改 mysql 数据库中的 user 表信息

使用 navicat 连接本地数据库,打开名为 mysql 的数据库,查询编辑 user 表信息,直接修改 Host 字段的中 localhost 值为%

参与本文讨论

请先登录 GitHub 后留言

0/500

本文留言

0

这篇文章还没有留言,来写第一条吧。

1 / 1