今天尝试在Ubuntu虚拟机上安装MySql 数据库(版本是:5.7.23-0Ubuntu0.18.04.1),数据库安装很简单,就是三行命令:

  1.  
    sudo apt-get install mysql-server # 下载安装mysql的服务端
  2.  
    sudo apt-get install mysql-client # 下载安装mysql的客户端
  3.  
    sudo apt-get install libmysqlclient-dev

但是,看似很顺利简单的安装过程,在第一次登陆的时候却遇到了麻烦。

  1.  
    ~$ mysql -u root -p
  2.  
    Enter password:
  3.  
    ERROR 1698 (28000): Access denied for user 'root'@'localhost'

然后,在网上找了很多的教程,最后实验成功的是这个方案:

解决步骤:

(1) 停止mysql服务:

~$ sudo service mysql stop

(2)以安全模式启动MySQL:

~$ sudo mysqld_safe --skip-grant-tables &

(3)MySQL启动之后就可以不用密码登陆了:

  1.  
    ~$ mysql -u root
  2.  
    Welcome to the MySQL monitor. Commands end with ; or \g.
  3.  
    Your MySQL connection id is 2
  4.  
    Server version: 5.7.10 MySQL Community Server (GPL)

(4)查看一下user表,错误的起因就是在这里, root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password。

  1.  
    mysql> select user, plugin from mysql.user;
  2.  
    +-----------+-----------------------+
  3.  
    | user | plugin |
  4.  
    +-----------+-----------------------+
  5.  
    | root | auth_socket |
  6.  
    | mysql.sys | mysql_native_password |
  7.  
    | dev | mysql_native_password |
  8.  
    +-----------+-----------------------+
  9.  
    3 rows in set (0.01 sec)

(5)关于auth_socket,在官方有说明: https://dev.mysql.com/doc/mysql-security-excerpt/5.5/en/socket-authentication-plugin.html ,反正现在暂时不用它, 那就把这里改了。

  1.  
    mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
  2.  
    Query OK, 1 row affected, 1 warning (0.00 sec)
  3.  
    Rows matched: 1 Changed: 1 Warnings: 1
  4.  
     
  5.  
    mysql> flush privileges;
  6.  
    Query OK, 0 rows affected (0.00 sec)

(6)重启服务,问题就解决了:

  1.  
    ~$ sudo service mysql stop
  2.  
    ...
  3.  
    * MySQL Community Server 5.7.10 is stopped
  4.  
    ~$ sudo service mysql start
  5.  
    ..
  6.  
    * MySQL Community Server 5.7.10 is started
  7.  
    ~$ mysql -u root -p
  8.  
    Enter password:
  9.  
    Welcome to the MySQL monitor. Commands end with ; or \g.
  10.  
    Your MySQL connection id is 2
  11.  
    Server version: 5.7.10 MySQL Community Server (GPL)

解决MySql ERROR 1698 (28000) 错误:Access denied for user 'root'@'localhost'的更多相关文章

  1. (转载)解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes

    今天想用用MySQL 数据库  谁知道老提示 1045 access denied for user 'root'@'localhost' using password yes 最后在csdn 上找到 ...

  2. 解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes

    今天想用用MySQL 数据库  谁知道老提示 1045 access denied for user 'root'@'localhost' using password yes 最后在csdn 上找到 ...

  3. 数据库之MySQL ERROR 1698 (28000) 错误:Access denied for user 'root'@'localhost'" error【摘抄】

    声明:全文均摘抄于MySQL ERROR 1698 (28000) 错误 //错误起源: ~$ mysql -u root -p Enter password: ERROR 1698 (28000): ...

  4. CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

    连接mysql出错:CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for u ...

  5. MySQL ERROR 1698 (28000) 错误

    之前MySQL服务端本机上使用密码登陆root账号是没有问题的,但是今天不知道是因为动了哪里,登陆失败并有这个错误代码: ~$ mysql -u root -p Enter password: ERR ...

  6. mysql 创建帐号出现 Access denied for user 'root'@'localhost'错误(转载)

    从供应商那边接手一个MySQL数据库(数据库版本为5.7.21 MySQL Community Server (GPL)),在创建账号时遇到了“ERROR 1044 (42000): Access d ...

  7. eclipse不正常编译导致错误:Access denied for user 'root'@'localhost' (using password: YES)

    使用eclipse连接mysql报错:Access denied for user 'root'@'localhost' (using password: YES) 连接代码没有任何问题,网上找了很多 ...

  8. phpMyAdmin出现错误 Access denied for user 'root'@'localhost' (using password: NO)

    今天安装wmpp,之后启动后点击phpMyAdmin 报拒绝连接错误:#1045 - Access denied for user 'root'@'localhost' (using password ...

  9. 解决:MySQL 报错:1045 - Access denied for user 'root'@'localhost'(using password YES)

    一.前言 今年疯狂迷上了开源,只要看到好的开源项目,就会不顾一切一股脑扎进去研究,五一期间发现一个很好的关于众筹的开源项目,但不巧,这个项目竟然是 PHP 写的,没学过 PHP,自然对这个开源项目毫无 ...

随机推荐

  1. js实现输入密码之延迟星号和点击按钮显示或隐藏

    缘由 手机打开segmentfalut时,长时间不登陆了,提示要重新登陆,输入的过程中看到输入密码时,延迟后再变成密文,很好奇,所以捣鼓了一下.本文实现了两种密码展示 代码实现 1 先明后密 js实现 ...

  2. 《区块链DAPP开发入门、代码实现、场景应用》笔记5——区块链福利彩票的设计

    笔者一直强调,一定要利用区块链的特点来解决行业存在的问题,并且该问题最好用区块链解决或者说只能用区块链解决.彩票行业就是个例子. 在讲解代码之前,首先讲解一下业务设计,如图6.15所示. 图6.15 ...

  3. MongoDB 基本概念

    MongoDB和关系型数据库的对应关系 关系数据库 MongoDB 数据库   database 数据库   database 表格  table 集合  collection 行  row 文档  ...

  4. 1行Python代码制作动态二维码

    原文地址 https://blog.csdn.net/m0_38106923/article/details/100603516 GitHub网站参见:https://github.com/sylns ...

  5. 使用focusky制作展示动画

    一个协会要举办大会议,以前我帮着做了个图片视频,就是很多照片循环展示,配个背景音乐那种. 现在又找到我,我用focusky制作下,因很久不用,怎么使用也忘了,这个软件的操作逻辑也不太容易搞的清,主要是 ...

  6. Linux SSH 服务

    本篇写一些关于Linux网络中SSH服务的相关知识. 测试环境 名称 IP地址 host01 192.168.28.128 host02 192.168.28.129 host03 192.168.2 ...

  7. gRPC应用C++

    1.  gRPC简述 RPC,远程方法调用,就是像调用本地方法一样调用远程方法. gRPC是Google实现的一种RPC框架,基于HTTP/2标准设计,带来诸如双向流.流控.头部压缩.单 TCP 连接 ...

  8. Sleep和 SleepEx函数

    Sleep和 SleepEx函数的功能是在指定的执行时间内中止所在线程的执行. SleepEx扩展了Sleep的功能,在最短超时时间间隔已到的情况下恢复线程执行外,在以下两种情况下发生时也可以恢复执行 ...

  9. aspose将word转pdf时乱码,或者出现小方框问题

    通常来讲,出现这种问题一般是因为Linux服务器没有安装中文字体  查看Linux目前的所有字体 fc-list #查看Linux目前的所有中文字体 fc-list :lang=zh #将window ...

  10. python3学习之lambda+sort

    >>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')] >>> pairs.sort(key ...