Ubuntu解决 MariaDB无密码就可以登录的问题

 

 

使用apt-get来安装mysql,安装好之后发现安装的是 MariaDB,如下,无需密码既可以登录了。即使使用mysqladmin或mysql_secure_installation 设置好密码,用密码登录可以,不用密码登录也可以。

去google了很久,终于有发现了,是用户插件问题。

参见这里:https://nixmash.com/post/fix-for-mysql-rootlocalhost-access-denied-on-new-installs

 

跟安装正常的mysql来比较下,如下

正常mysql
mysql> select user, plugin from mysql.user where plugin = 'mysql_native_password';
+-----------+-----------------------+
| user      | plugin                |
+-----------+-----------------------+
| root      | mysql_native_password |
+-----------+-----------------------+
8 rows in set (0.00 sec)


不正常的
MariaDB [(none)]> select user, plugin from mysql.user;
+------+-------------+
| user | plugin      |
+------+-------------+
| root | unix_socket |
+------+-------------+
1 row in set (0.00 sec)

 

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

 

解决方法:

 

root@ubuntu16:~# mysqld_safe --skip-grant-tables
root@ubuntu16:~# mysql
MariaDB [(none)]> UPDATE mysql.user SET authentication_string = PASSWORD('123456'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]> select user, plugin from mysql.user;
+------+-----------------------+
| user | plugin                |
+------+-----------------------+
| root | mysql_native_password |
+------+-----------------------+
1 row in set (0.00 sec)


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

 

参考:https://www.cnblogs.com/Dicky-Zhang/p/8000584.html

posted @ 2018-09-18 15:24  钟桂耀  阅读(448)  评论(0编辑  收藏  举报