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>
  • 相关阅读:
    Matrix Power Series
    Recursive sequence HDU5950
    P2151 [SDOI2009]HH去散步
    P4273 [NOI2004] 降雨量
    P1034 [NOIP2002 提高组] 矩形覆盖
    P1027 [NOIP2001 提高组] Car 的旅行路线
    Win10使用Dism++离线安装.Net3.5
    WPF之模板
    WPF之资源
    WPF之命令
  • 原文地址:https://www.cnblogs.com/lvhanzhi/p/10530164.html
Copyright © 2011-2022 走看看