问题:

困扰了很久的问题,,

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

 root@ubuntu:/etc/mysql# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.0.-MariaDB-0ubuntu0.16.04. Ubuntu 16.04 Copyright (c) , , 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,跳过密码验证

过滤了下没有

 root@ubuntu:~# cd /etc/mysql/
root@ubuntu:/etc/mysql# pwd
/etc/mysql
root@ubuntu:/etc/mysql# ls -l
总用量
drwxr-xr-x root root 12月 : conf.d
-rw------- root root 12月 : debian.cnf
-rw------- root root 12月 : debian.cnf-5.7
-rwxr-xr-x root root 7月 : debian-start
-rw-r--r-- root root 7月 : mariadb.cnf
drwxr-xr-x root root 12月 : mariadb.conf.d
lrwxrwxrwx root root 12月 : my.cnf -> /etc/alternatives/my.cnf
-rw-r--r-- root root 1月 my.cnf.fallback
-rw-r--r-- root root 2月 mysql.cnf
drwxr-xr-x root root 12月 : mysql.conf.d
root@ubuntu:/etc/mysql# grep "skip-grant-tables" -r
root@ubuntu:/etc/mysql#

看看my.cnf里面是不是把密码写进去了,查找了相关.cnf文件去看了看也没有

 root@ubuntu:~# 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/-mysqld_safe.cnf
/etc/mysql/mariadb.conf.d/-mysql-clients.cnf
/etc/mysql/mariadb.conf.d/-client.cnf
/etc/mysql/mariadb.conf.d/-server.cnf
/etc/mysql/debian.cnf
/var/lib/dpkg/alternatives/my.cnf
root@ubuntu:~#

不过有个小发现,

  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 看了说明是以上由脚本生成,不要改动,
虽然这样写,我也去改了下,加上密码,重启还是不行

最后的最后,,,,去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 |
+-----------+-----------------------+
rows in set (0.00 sec)
 不正常的

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

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

如下:

 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 [(none)]> select user, plugin from mysql.user
-> ;
+------+-----------------------+
| user | plugin |
+------+-----------------------+
| root | mysql_native_password |
+------+-----------------------+
row in set (0.01 sec) 先杀死mysql kill - pid
启动:
sudo service mysql start

最后验证下:需要密码了

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

解决 MariaDB无密码就可以登录的问题的更多相关文章

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

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

  2. 快速解决MariaDB无密码就可以登录的问题

    mysql  Ver 15.1 Distrib 10.1.37-MariaDB, for Linux (x86_64) using readline 5.1 #mysql -uroot -p #del ...

  3. mariadb新安装解决远程访问以及root登录

    mariadb新安装解决远程访问以及root登录一.修改/etc/mysql/my.conf找到bind-address = 127.0.0.1这一行直接#掉或者改为bind-address = 0. ...

  4. Linux SSH实现无密码远程登录

      一.      SSH无密码远程登录原理 二.      SSH实现无密码远程登录 实现主机A 无密码远程登录主机B 主机A   IP地址:10.8.9.154 主机B   IP地址:10.8.9 ...

  5. Postman+Postman interceptor的安装和使用-解决把chrome浏览器登录状态同步到postman进行有依赖的接口测试 Postman 使用方法详解

    Postman+Postman interceptor的安装和使用-解决把chrome浏览器登录状态同步到postman进行有依赖的接口测试   问题引入:做接口测试时,有依赖关系的接口往往不好测试( ...

  6. Mac 无密码 SSH 登录服务器

    Mac 无密码 SSH 登录服务器,只需要简单三步,不再需要记住账号密码,快速进入服务器 第一步,生成密钥对 在当前用户下创建.ssh目录 mkdir ~/.ssh 使用命令ssh-keygen生成密 ...

  7. 解决mariadb grant ERROR 1045 (28000): Access denied for user

    下面我们一起来看一篇解决mariadb grant ERROR 1045 (28000): Access denied for user问题,希望文章能够帮助到各位朋友.   用mariadb也有一段 ...

  8. ssh连接原理介绍( 无密码连接登录的原理)

    SSH(Secure  Shell)一种在不安全网络上提供安全远程登录及其它安全网络服务的协议.由客户端和服务端的软件组成的,有两个不兼容的版本分别是:1.x和2.x.(SSH 2.x的客户程序是不能 ...

  9. 解决mariadb数据库服务无法开启

    我的系统Manjaro linux,安装的数据库为mariadb 10.1 1.安装数据库 pacman -S mariadb 2.配置数据库启动环境: mysql_install_db --user ...

随机推荐

  1. Selenium自动化-CSS元素定位

    接下来,开始讲解 CSS元素定位. CSS定位速度快,功能多,但是不能向上查找,比 xpath好用,是本人认为最好用的定位方式   大致用法总结: 具体使用仿上篇博客.http://www.cnblo ...

  2. 手机端两端对齐,兼容ios,安卓

    .div-title p label{ text-align: justify; width: 18%; display: inline-block; text-align-last: justify ...

  3. java 应用程序的编译和运行

    1.java 文件的编译和执行步骤. 第一步:使用编辑器编辑  后缀为java的文件,里面包含主类(包含 main()函数), 源文件的命名规则是,如果源文件中有多个类,那么只能有一个类是public ...

  4. eclipse如何修改android工程的包名?

    在我们android项目开发到一定的程度时由于需要,我们必须修改一下工程的包名,以便更好的发布我们的项目.但是在这个过程中有时候修改好了之后会出现一些错误.下面由小编一步步教你如何更改包名,和解决出现 ...

  5. 章节九、3-Desired Capabilities介绍

    一.Desired Capabilities是selenium webdrive中已经写好的一个类,我们可以通过它来告诉selenium webdrive在Desired Capabilities是什 ...

  6. Git命令备忘

    最近在用Git,查了点相关资料,逻辑依然不太明了,先整理一部分备忘,以后补充 一.本地Git与Github/码云的关联 1. 设置本地用户名,邮箱 git config --global user.n ...

  7. 如何设置Oracle数据库客户端字符集以及系统中的NLS_LANG环境变量

    概述: 本地化是系统或软件运行的语言和文化环境.设置NLS_LANG环境参数是规定Oracle数据库软件本地化行为最简单的方式. NLS_LANG参数不但指定了客户端应用程序和Oracle数据库所使用 ...

  8. Tomcat与Nginx服务器的配合使用及各自的区别

    Nginx常用做静态内容服务和反向代理服务器,以及页面前端高并发服务器.适合做负载均衡,直面外来请求转发给后面的应用服务(tomcat ,django什么的),Tomcat更多用来做做一个应用容器,让 ...

  9. ES6 快速入门

    ES6 初识 ES6 是 ECMAScript 6.0 的简写,即 JavaScript 语言的下一代标准,已经在 2015年6月正式发布了,它的目标是让JS能够方便的开发企业级大型应用程序,因此,E ...

  10. CSS---选择器种类 | 层叠性权重

    一.css选择器种类 1.1,ID选择器 1.2,类选择器 1.3,标签选择器 1.4,后代选择器 1.5,子代选择器 1.6,交集选择器 1.7,并集选择器 1.8,通配符选择器 1.9,属性选择器 ...