MySQLl允许远程登录配置_MySQL
程序员文章站
2022-05-19 09:21:36
...
mysql -h 10.17.11.187 -uroot -ploushang
开启远程登录步骤:
1, 登录 Mysql-Server 连接本地 mysql (默认只允许本地连接)
2, 修改 Mysql-Server 用户配置
mysql> USE mysql; -- 切换到 mysql DB
Database changed
mysql> SELECT User, Password, Host FROM user; -- 查看现有用户,密码及允许连接的主机
+------+----------+-----------+
| User | Password | Host |
+------+----------+-----------+
| root | | localhost |
+------+----------+-----------+
1 row in set (0.00 sec)
mysql> -- 只有一个默认的 root 用户, 密码为空, 只允许 localhost 连接
12
mysql> -- 下面我们另外添加一个新的 root 用户, 密码为空, 只允许 192.168.1.100 连接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;
mysql> -- @'192.168.1.100'可以替换为@‘%’就可任意ip访问,当然我们也可以直接用 UPDATE 更新 root 用户 Host, 但不推荐, SQL如下:
mysql> -- UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1;
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
复制代码
修改root密码
mysql> use mysql
Database changed
mysql> update user set password=PASSWORD('123456') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
开启远程登录步骤:
1, 登录 Mysql-Server 连接本地 mysql (默认只允许本地连接)
2, 修改 Mysql-Server 用户配置
mysql> USE mysql; -- 切换到 mysql DB
Database changed
mysql> SELECT User, Password, Host FROM user; -- 查看现有用户,密码及允许连接的主机
+------+----------+-----------+
| User | Password | Host |
+------+----------+-----------+
| root | | localhost |
+------+----------+-----------+
1 row in set (0.00 sec)
mysql> -- 只有一个默认的 root 用户, 密码为空, 只允许 localhost 连接
12
mysql> -- 下面我们另外添加一个新的 root 用户, 密码为空, 只允许 192.168.1.100 连接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;
mysql> -- @'192.168.1.100'可以替换为@‘%’就可任意ip访问,当然我们也可以直接用 UPDATE 更新 root 用户 Host, 但不推荐, SQL如下:
mysql> -- UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1;
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
复制代码
修改root密码
mysql> use mysql
Database changed
mysql> update user set password=PASSWORD('123456') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
下一篇: Oracle数据更改后出错怎么做?