mysql8.0 root修改密码并开启远程访问权限

进入mysql命令行后

1、修改密码

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)

注:在mysql8版本中更改用户密码须要加入with mysql_native_password,而且要加入;因此一下两种写法都是不对的。
alter user 'root'@'localhost' identified by 'amp';
alter user 'root'@'localhost' identified with mysql_native_password by 'amp'

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

2、修改远程访问

use mysql

select host,user from user;

结果:

复制代码
mysql> use mysql
Database changed
mysql> select host,user form user;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'user'
 at line 1
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)
复制代码

执行命令

update user set host='%' where user='root';

flush privileges;

结果:

复制代码
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

再次查询修改后结果,OK。结果以下:

mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)
复制代码

最后远程登录测试一下。

posted @   tt1234  阅读(5467)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示