红联Linux门户
Linux帮助

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

发布时间:2017-12-08 09:25:40来源:linux网站作者:Dicky_Zhang
问题:
困扰了很久的问题
使用apt-get来安装mysql,安装好之后发现安装的是 MariaDB,如下,无需密码既可以登录了。即使使用mysqladmin设置好密码,用密码登录可以,不用密码登录也可以
[email protected]:/etc/mysql# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 10.0.31-MariaDB-0ubuntu0.16.04.2 Ubuntu 16.04
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
排查思路:
第一看看my.conf有没有skip-grant-tables,跳过密码验证
过滤了下没有
解决MariaDB无密码就可以登录的问题
看看my.cnf里面是不是把密码写进去了,查找了相关.cnf文件去看了看也没有
[email protected]:~# find / -name "*.cnf"
/usr/share/ssl-cert/ssleay.cnf
/usr/share/dovecot/dovecot-openssl.cnf
/usr/lib/ssl/openssl.cnf
/etc/ssl/openssl.cnf
/etc/alternatives/my.cnf
/etc/mysql/my.cnf
/etc/mysql/mariadb.cnf
/etc/mysql/conf.d/mysqldump.cnf
/etc/mysql/conf.d/mysql.cnf
/etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf
/etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
/etc/mysql/mariadb.conf.d/50-client.cnf
/etc/mysql/mariadb.conf.d/50-server.cnf
/etc/mysql/debian.cnf
/var/lib/dpkg/alternatives/my.cnf
[email protected]:~# 
不过有个小发现:
vim /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = root
password = 
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = root
password = 
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr
看了说明是以上由脚本生成,不要改动,
虽然这样写,我也去改了下,加上密码,重启还是不行
最后的最后,去搜索了很久,终于有发现了,是用户插件问题。
第一我去跟安装正常的mysql来比较下,如下
解决MariaDB无密码就可以登录的问题
解决MariaDB无密码就可以登录的问题
看到这里应该发现问题了,按照正常的修改就行了
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables
进去mysql执行如下命令:
MariaDB [(none)]> UPDATE mysql.user SET authentication_string = PASSWORD('mypassword'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
验证:
解决MariaDB无密码就可以登录的问题
先kill掉mysql  kill -9 pid
启动:
sudo service mysql start
最后验证下:需要密码了
[email protected]:~# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[email protected]:~#
 
本文永久更新地址:http://www.linuxdiyf.com/linux/32993.html