zoukankan      html  css  js  c++  java
  • mysql初始化密码错误

    ubuntu19
    固态硬盘到手后,安装ubuntu19,之后安装好mysql,但是在用命令登陆数据库的时候报错:
    sudo apt install mysql-server#安装MySQL
    mysql -u root -p#登录
    access denied for user root@localhost#报错
    1
    2
    3
    于是我在mysqld.cnf文件末尾添加skip-grant-tables,保存之后重启mysql 服务并登录,直接按enter键进入了数据库
    sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
    #在文件末尾添加skip-grant-tables
    service mysql restart #重启mysql服务
    mysql -u root -p#登录
    1
    2
    3
    4
    3.于是令authentication=’’,将skip-grant-tables注释重启mysql服务,然后也可以登陆数据库

    update user set authentication_string='' where user='root';#root不设置密码
    service mysql restart #在这之前记得要注释掉skip-grant-tables
    1
    2
    如果我们想给root用户设置密码怎么办呢?
    update user set plugin='mysql_native_password' where user='root'; #更改加密方式
    alter user 'root'@'localhost' IDENTIFIED BY '123456';#设置密码
    FLUSH PRIVILEGES;
    1
    2
    3
    然后就可以使用密码登陆了(mysql 的 root用户中有几个 password="", 为了安全起见用 delete 命令删除就行)
    deepin15 (已经验证,没有错误)
    在deepin 中安装MySQL(MariaDB):
    sudo apt install mysql-server
    1
    登录mysql(MariaDB),在root权限下可以直接登录,当然也可以想上文Ubuntu中一样加入skip-grant-tabels
    sudo mysql -u root -p
    1
    可以看到新版的MariaDB中使用unix-socket加密,我们将plugin修改为mysql_native_password
    use mysql
    update user set plugin='mysql_native_password' where user='root';
    1
    2
    然后我们就可以设置密码了
    update user set password=password('123456') where user='root'
    update user set authentication_string=password('123456') where user='root'
    如果上面报错的话,可以尝试执行:
    alter user 'root'@'localhost' identified by '123456'
    1
    2
    3
    4
    重启服务,登陆
    exit
    service mysql restart#重启服务
    mysql -u root -p #登陆
    1
    2
    3
    注意虽然作者竭力想写地准确无错,但仍会有所忽略,请多包含
    重点就是将root用户的加密方式plugin修改为mysql_native_password(真的吗?好像我在创建普通用户的时候不用诶?等我下一次重装数据库的时候再来验证吧,现在我真的不想验证,要吐了)
    这是作者第二次修正了(ubuntu部分),欢迎各位读者指正
    本文参考:mysql8.XXX版本以后重置密码,修改加密方式解决Authentication plugin ‘XXX’ cannot be loaded问题
    扩展阅读:mysql创建普通用户,并用其创建数据库

  • 相关阅读:
    触摸屏与usb鼠标同时支持
    QT国际化(lupdate/linguits/lrelease)生成.ts,转换成.qm方法
    Qt5 使用lambda
    c++中lambda表达式的用法
    异或运算的作用
    函数指针和指针函数用法和区别
    前端html页面学习---html部分
    二:maven构建module
    一:使用maven构建项目
    maven项目发布到tomcat后没有lib目录解决方案
  • 原文地址:https://www.cnblogs.com/onesea/p/15029323.html
Copyright © 2011-2022 走看看