新版本Mariadb安装后相关问题的解决

给新机器Ubuntu安装的Mariadb后无法登录,通过网上各种方法修改root用户密码,仍然无法解决,耗费几个小时!

经过看日志和查手册,发现原因如下:

  1. ubuntu确实安装没有启用root用户,所以没有root用户密码,而新安装的mariadb使用的系统root的密码(初始安装后)
  2. 通过原来的方法重置password无效(原因就是采用了unix_socket认证)

那么,解决方法如下: 直接进入root用户下,就可以免密码登录!

对于ubuntu而言,需要启用root用户密码,方法如下:

sudo passwd1

输入sudo的密码后,再次输入两次root用户密码后即可。

然后,

xx>su - root root>mysql -u root //直接回车就可以进入,无需密码,无论什么密码也行,因为他不需要! mysql>1 2 3

如果,你希望采用原来的mysql密码方式,需要修改认证插件,方法如下:

// 切换到root用户, 无需密码进入Mysql update mysql.user set plugin='mysql_native_password' where user='root'; update mysql.user set password=password("您的密码") where user='root'; FLUSH PRIVILEGES;1 2 3 4

这样就可以在任何用户下访问mysql了。

为啥要升级成缺省为unix_socket呢?

对于CentOS,RedHat而言,使用root用户时,无需密码登录。 而且,也符合安全准则,新版本的MySQL密码会在日志中输出,MariaDB以前保持空密码,现在意味着,用root用户,无需登录。

 

第一我去跟安装正常的mysql来比较下,如下

复制代码
复制代码
1 正常mysql
2 mysql> select user, plugin from mysql.user where plugin = 'mysql_native_password';
3 +-----------+-----------------------+
4 | user      | plugin                |
5 +-----------+-----------------------+
6 | root      | mysql_native_password |
7 +-----------+-----------------------+
8 8 rows in set (0.00 sec)
复制代码
复制代码
复制代码
复制代码
1 不正常的
2 
3 MariaDB [(none)]> select user, plugin from mysql.user;
4 +------+-------------+
5 | user | plugin      |
6 +------+-------------+
7 | root | unix_socket |
8 +------+-------------+
9 1 row in set (0.00 sec)
复制代码
复制代码

看到这里应该发现问题了,按照正常的修改就行了

如下:

复制代码
复制代码
 1 sudo service mysql stop
 2 sudo mysqld_safe --skip-grant-tables
 3 进去mysql执行如下命令:
 4 MariaDB [(none)]> UPDATE mysql.user SET authentication_string = PASSWORD('mypassword'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
 5 MariaDB [(none)]> FLUSH PRIVILEGES;
 6 验证:
 7 MariaDB [(none)]> select user, plugin from mysql.user
 8     -> ;
 9 +------+-----------------------+
10 | user | plugin                |
11 +------+-----------------------+
12 | root | mysql_native_password |
13 +------+-----------------------+
14 1 row in set (0.01 sec)
15 
16 先杀死mysql  kill -9 pid
17 启动:
18 sudo service mysql start
复制代码
复制代码

最后验证下:需要密码了

root@ubuntu:~# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
root@ubuntu:~# 

 

posted on   剩余价值  阅读(934)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示