zoukankan      html  css  js  c++  java
  • ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    centos7.5 登录数据库报错

    问题:

    [root@db02-52 ~]# mysql -uroot -p123
    Warning: Using a password on the command line interface can be insecure.
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    

    原因1:数据库中的root用户被误删除

    解决方法:

    方法一:

    1)停止数据库
    [root@db01-51 ~]# /etc/init.d/mysqld stop
    2)跳过授权表,跳过网络启动数据库
    [root@db01-51 ~]# mysqld_safe --skip-grant-tables --skip-networking &
    3)连接数据库
    [root@db01-51 ~]#  mysql
    4)插入新root用户
    insert into mysql.user values ('localhost','root',PASSWORD('123'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N');
    5)重启MySQL
    [root@db01-51 ~]# mysqladmin shutdown
    [root@db01-51 ~]# /etc/init.d/mysqld start
    Starting MySQL. SUCCESS! 
    6)连接数据库
    [root@db01-51 ~]# mysql -uroot -p123
    mysql> 
    

    方法二:

    1)停止数据库
    [root@db02-52 ~]# /etc/init.d/mysqld stop
    2)跳过授权表,跳过网络启动数据库
    [root@db02-52 ~]# mysqld_safe --skip-grant-tables --skip-networking &
    3)连接数据库
    [root@db02-52 ~]# mysql
    4)刷新授权表
    mysql> flush privileges;
    5)创建root超级用户
    mysql> grant all on *.* to root@'localhost' identified by '123' with grant option;
    6)重启MySQL
    [root@db02-52 ~]# mysqladmin -uroot -p123 shutdown
    [root@db02-52 ~]# /etc/init.d/mysqld start
    7)登录数据库
    [root@db02-52 ~]# mysql -uroot -p123
    mysql> 
    

    原因二:密码错误

    解决方法:修改密码

    [root@db02-52 ~]# vim /etc/my.cnf
    skip-grant-tables
    [root@db02-52 ~]# /etc/init.d/mysqld restart
    [root@db02-52 ~]# mysql
    mysql> update mysql.user set password=PASSWORD('111') where user='root' and host='localhost';
    [root@db02-52 ~]# vim /etc/my.cnf
    skip-grant-tables	#删掉这一行
    [root@db02-52 ~]# /etc/init.d/mysqld restart
    [root@db02-52 ~]# mysql -uroot -p111
    mysql> 
    

    原因三:mysql反向解析

    解决方法:

    [root@db02-52 ~]# vim /etc/my.cnf
    skip-name-resolve
    重启数据库
    [root@db02-52 ~]# mysql -uroot -p123 -h 127.0.0.1
    mysql>
  • 相关阅读:
    Excel导出工具
    载入Properties文件中的配置项信息
    对list进行排序-重写排序规则
    Mysql 5.7版本报错 1055
    SVN客户端与服务端安装详解
    持续集成的理解
    js 日期格式化
    mysql多个时间戳字段默认值问题
    eclipse svn插件地址
    orientationchange移动端横竖屏切换属性
  • 原文地址:https://www.cnblogs.com/lvhanzhi/p/10530164.html
Copyright © 2011-2022 走看看