今天尝试在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服务:

  1. ~$ sudo service mysql stop

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

  1. ~$ 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. k8s--yml文件

  2. 填坑——audio不能正常播放,控制台报错 Uncaught (in promise) DOMException

    原文:https://blog.csdn.net/Mariosss/article/details/87861167 用chrome调试页面时,发现audio控件有时不能正常播放音频,控制台报错 Un ...

  3. 供应链管理如何提高效率?APS系统成优化引擎

    APS系统,虽然它的起兴只有短短的十几年,但是在这段时间里面,它为很多企业解决了很多人工手动.脑力不可解决的问题. 所以APS被誉为供应链优化引擎,APS常常被称为高级计划与排程,但也有称为高级计划系 ...

  4. 1.live555源码分析----RSTPServer创建过程分析

    最近五一回家,终于有机会能安静的看一下流媒体这方面相关的知识,准备分析live555的源码,接下来会把我读源码的过程记录成博客,以供其他的同路人参考. 因为再读源码的过程中,并不是一路顺着读下来,往往 ...

  5. 【RAC】rac环境下的数据库备份与还原

    [RAC]rac环境下的数据库备份与还原 一.1  BLOG文档结构图 一.2  前言部分 一.2.1  导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~ ...

  6. Locust性能模块浅谈

    今天接触到Locust性能模块,下面介绍一下安装与简单的应用 1.安装方式:pip install Locust Locust支持Python 2.7, 3.4, 3.5, and 3.6的版本,小编 ...

  7. 服务器部署docker lnmp环境

    一.安装dockerDocker要求运行在Centos 7上,要求系统为64位,系统内核版本3.10以上 1.uname -an 查看当前系统版本 2.yum -y install docker 下载 ...

  8. Pthon魔术方法(Magic Methods)-hash

    Pthon魔术方法(Magic Methods)-hash 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.hash方法 __hash__: 内建函数hash()调用的返回值,返 ...

  9. Python入门篇-高阶函数

    Python入门篇-高阶函数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.高级函数  1>.First Class Object 函数在Python中是一等公民 函数也 ...

  10. MSF MS11-050攻击实践及内存保护技术

    内存攻击指的是攻击者利用软件安全漏洞,构造恶意输入导致软件在处理输入数据时出现非预期错误,将输入数据写入内存中的某些特定敏感位置,从而劫持软件控制流,转而执行外部输入的指令代码,造成目标系统被获取远程 ...