登录
首页 >  数据库 >  MySQL

Linux 下安装 MySQL 后给 root 用户设置密码

来源:SegmentFault

时间:2023-01-28 16:10:29 452浏览 收藏

在数据库实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《Linux 下安装 MySQL 后给 root 用户设置密码》,聊聊MySQL、Linux、计算机网络,希望可以帮助到正在努力赚钱的你。

Linux 下通过

MySQL root@(none):mysql> SELECT `User`,`Host`,plugin,authentication_string FROM `user`;
+------------------+-----------+-----------------------+-------------------------------------------------------------------------------+
| User             | Host      | plugin                | authentication_string                                                         |
+------------------+-----------+-----------------------+-------------------------------------------------------------------------------+
| debian-sys-maint | localhost | caching_sha2_password | $A$005$P|    x1 ^Ew^A^A^X    `\rNk(N^GR9HPKy4yvB.RcWyyDuPMHGIrVSXzTjGR5BeZC85qTUP3 |
| mysql.infoschema | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED        |
| mysql.session    | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED        |
| mysql.sys        | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED        |
| root             | localhost | auth_socket           |                                                                               |
+------------------+-----------+-----------------------+-------------------------------------------------------------------------------+

运行下面这条语句,将root账户的验证插件修改为

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '12345';

然后刷新权限使得设置生效

FLUSH PRIVILEGES;

设置完成后,

MySQL root@(none):mysql> SELECT `User`,`Host`,plugin,authentication_string FROM `user`;
+------------------+-----------+-----------------------+-------------------------------------------------------------------------------+
| User             | Host      | plugin                | authentication_string                                                         |
+------------------+-----------+-----------------------+-------------------------------------------------------------------------------+
| debian-sys-maint | localhost | caching_sha2_password | $A$005$P|    x1 ^Ew^A^A^X    `\rNk(N^GR9HPKy4yvB.RcWyyDuPMHGIrVSXzTjGR5BeZC85qTUP3 |
| mysql.infoschema | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED        |
| mysql.session    | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED        |
| mysql.sys        | localhost | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED        |
| root             | localhost | caching_sha2_password | $A$019$1^Ac!u@^Qto                                                              |
+------------------+-----------+-----------------------+-------------------------------------------------------------------------------+

这样就可以用密码登录mysql的root用户了。

有些教程会教你使用

mysql_native_password
作为验证插件,这个是旧版本mysql提供的插件,使用中和
caching_sha2_password
体验一样。如果不是要通过一些不兼容
caching_sha2_password
的客户端连接mysql服务端,显然还是用新插件更安全。

理论要掌握,实操不能落!以上关于《Linux 下安装 MySQL 后给 root 用户设置密码》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表