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

    MySQL安装完server端和客户端后,登录Mysql时报错:
    [root@rhel204 MySQL 5.6.23-RMP]# mysql
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    [root@rhel204 MySQL 5.6.23-RMP]# service mysql start
    Starting MySQL.[ OK ]
    [root@rhel204 MySQL 5.6.23-RMP for oraclelinux or rhel5-x86-64V74393-01]# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO
    安装过程中并没有设置过任何密码,重装多次也是如此。。。。。
    ==========================
    处理方法:
    Reset Forgotten MySQL Root Password:
    First things first. Log in as root and stop the mysql daemon.

    sudo /etc/init.d/mysql stop

    Now lets start up the mysql daemon and skip the grant tables which store the passwords.

    sudo mysqld_safe --skip-grant-tables&

    (press Ctrl+C now to disown the process and start typing commands again)

    You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

    sudo mysql --user=root mysql

    update user set password=password('new-password');
    flush privileges;
    exit;

    Now kill your running mysqld then restart it normally.

    sudo killall mysqld_safe&
    (press Ctrl+C now to disown the process and start typing commands again)
    /etc/init.d/mysql start

    You should be good to go. Try not to forget your password again.

    https://www.howtoforge.com/reset-forgotten-mysql-root-password

    http://www.cnblogs.com/khler/archive/2011/02/10/1950819.html

    [root@rhel201 mysql]# mysql -uroot -p  --使用上面修改的新密码登录 
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.6.23-enterprise-commercial-advanced
    
    Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> show databases;  
    ERROR 1820 (HY000): You must SET PASSWORD before executing this statement  
    mysql> exit
    Bye

    需要重新修改密码:

    [root@rhel201 mysql]# mysqladmin -uroot -p password rusky  --将密码修改为rusky
    Enter password: 
    mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'root'@'localhost' (using password: YES)'
    [root@rhel201 mysql]# mysqladmin -uroot -p password rusky
    Enter password: 
    mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'root'@'localhost' (using password: YES)'
    [root@rhel201 mysql]# mysqladmin -uroot -p password rusky
    Enter password: 
    Warning: Using a password on the command line interface can be insecure.
    [root@rhel201 mysql]# mysql -uroot -p  --使用新密码登录正常。
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 13
    Server version: 5.6.23-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)
    
    Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> 

     ==========

    问题补充:

    2015-04-14 17:13:08 15472 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
    2015-04-14 17:13:08 15472 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
    A random root password has been set. You will find it in '/root/.mysql_secret'.
    2015-04-14 17:13:10 15472 [Note] Binlog end

    新版本的mysql安装过程中创建一个新的随机密码:

    [root@rusky~]# cat .mysql_secret
    # The random password set for the root user at Tue Apr 14 17:13:09 2015 (local time): VUbNaGLLtAU546Nh

    登录命令:mysql -uroot -pVUbNaGLLtAU546Nh --使用文件中的随机密码可正常登录。

    [root@NOP6-citrix01 local]# mysqladmin -uroot -p password  --修改密码
    Enter password: VUbNaGLLtAU546Nh 
    New password:  新密码
    Confirm new password: 新密码
    [root@NOP6-citrix01 local]# 
  • 相关阅读:
    php大力力 [048节] php一点支付开发资料,很散
    php大力力 [047节] 寻找程序员的方法和应用
    ECharts的简单使用
    xlsxwriter新建Excel文件-制图
    xlsxwriter新建Excel文件
    xlrd读取Excel文件
    抽奖概率互斥算法
    Redis 的 8 大数据类型!
    Django Web框架入门-博客(更新完成)
    Git学习
  • 原文地址:https://www.cnblogs.com/rusking/p/4422326.html
Copyright © 2011-2022 走看看