Linux mysql 5.6: ERROR 1045 (28000): Access denied for user & #39; root & #39; @ & #39; localhost & #39; (using password: NO ), 28000 denied

Source: Internet
Author: User

Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO), 28000 denied

Recently, mysql 5.6 has encountered the following problems.

Thank you for sharing the original article:

CASE Environment:

Operating System:Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64 bit

Database Version:Mysql 5.6.19 64 bit

Case study:

I started to learn mysql this day and installed Mysql 5.6.19 64bit database. The installation was successful, but I encountered ERROR 1045 (28000) when using root login ): access denied for user 'root' @ 'localhost' (using password: NO) error. as shown below

[root@DB-Server tmp]# rpm -ivh MySQL-server-5.6.19-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
[root@DB-Server tmp]# rmp -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm 
-bash: rmp: command not found
[root@DB-Server tmp]# rpm -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[root@DB-Server tmp]# /etc/rc.d/init.d/mysql status
MySQL is not running[FAILED]
[root@DB-Server tmp]# /etc/rc.d/init.d/mysql start
Starting MySQL.[  OK  ]
[root@DB-Server tmp]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@DB-Server tmp]# mysql -u root mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

The root password has not been set during the installation process. If you do not know the root password, you can search for the following information on the Internet:

1: Some blogs say that the root random password is in/root/. mysql_secret, but I have no/root/. mysql_secret file in this version. I found an article with the following general idea (no confirmation ). I still don't understand why I didn't generate this file in this version?

ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO): NO temporary root password is generated.

ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: YES): indicates that the temporary password of root is generated.

2: Some documents indicate that the default password of root is blank. It is confirmed that it is the old version. For Mysql 5.6 and later versions, the root password is no longer blank due to security considerations.

In addition, I found many people on the official website that encountered similar problems: ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)

Solution:

Stop the mysql server first.

[root@DB-Server init.d]# /etc/rc.d/init.d/mysql stop
 
 Shutting down MySQL..[ OK ]
 

Then run the mysqld_safe command to start mysql and update the password of the root account.

-- Skip-grant-tables: Do not start grant-tables (Authorization Table), skip permission control.

-- Skip-networking: skip the TCP/IP protocol and only access it from the Local Machine (this option is not required according to some information on the Internet. No)

[root@DB-Server init.d]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[2] 9396
[root@DB-Server init.d]# 140722 14:59:46 mysqld_safe Logging to '/var/lib/mysql/DB-Server.err'.
140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

After executing the above command, this session window will be unresponsive, you need to use CTRL + C to interrupt the session, check/var/lib/mysql/DB-Server.err log, no other exception information is found. I didn't understand why the session window was unresponsive.

tail -200 /var/lib/mysql/DB-Server.err | more
 
2014-07-22 14:59:41 9346 [Note] Shutting down plugin 'binlog'
2014-07-22 14:59:41 9346 [Note] /usr/sbin/mysqld: Shutdown complete
 
140722 14:59:41 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2014-07-22 14:59:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timesta
mp server option (see documentation for more details).
2014-07-22 14:59:47 9516 [Note] Plugin 'FEDERATED' is disabled.
2014-07-22 14:59:47 9516 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-07-22 14:59:47 9516 [Note] InnoDB: The InnoDB memory heap is disabled
2014-07-22 14:59:47 9516 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-07-22 14:59:47 9516 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-07-22 14:59:47 9516 [Note] InnoDB: Using Linux native AIO
2014-07-22 14:59:47 9516 [Note] InnoDB: Using CPU crc32 instructions
2014-07-22 14:59:47 9516 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-07-22 14:59:47 9516 [Note] InnoDB: Completed initialization of buffer pool
2014-07-22 14:59:47 9516 [Note] InnoDB: Highest supported file format is Barracuda.
2014-07-22 14:59:47 9516 [Note] InnoDB: 128 rollback segment(s) are active.
2014-07-22 14:59:47 9516 [Note] InnoDB: Waiting for purge to start
2014-07-22 14:59:47 9516 [Note] InnoDB: 5.6.19 started; log sequence number 1626087
2014-07-22 14:59:47 9516 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.6.19'  socket: '/var/lib/mysql/mysql.sock'  port: 0  MySQL Community Server (GPL)

-> From user

    -> where user='root' and host='root' or host='localhost';
+-----------+------+-------------------------------------------+------------------+
| Host      | User | Password                                  | password_expired |
+-----------+------+-------------------------------------------+------------------+
| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y                |
+-----------+------+-------------------------------------------+------------------+
1 row in set (0.00 sec)
 
mysql> update user set password=PASSWORD('p12#456')
    -> where user='root' and host='root' or host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

After setting a new user or changing the password, use flush privileges to refresh the MySQL system permission table. Otherwise, access is denied. Another method is to restart the mysql server, to make the new settings take effect.

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit
Bye
[root@DB-Server init.d]# /etc/rc.d/init.d/mysql restart
Shutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
[  OK  ]
Starting MySQL.[  OK  ]
[2]-  Done                    mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@DB-Server init.d]# mysql -u root p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@DB-Server init.d]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.19
 
Copyright (c) 2000, 2014, 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> 

In addition, if ERROR 1820 (HY000): You must set password before executing this statement occurs after logging on to the mysql database, You can reset the PASSWORD to solve the problem.

mysql>set password = password('p12#456'); 

 

Now the problem is solved, but there are still some questions. Why is this error? In fact, all these materials are about solutions, but they all shy away from the causes.

References:

Http://huangyifa163.blog.163.com/blog/static/262875752011127102215790/

Http://sundful.iteye.com/blog/704337

Http://wenku.baidu.com/view/735ffa41be1e650e52ea995a.html

Http://www.cnblogs.com/sunson/articles/2172086.html

Http://blog.163.com/eric1945@126/blog/static/164934572201081494343373/

Http://www.cnblogs.com/likai198981/archive/2013/04/06/3002518.html

Author: Xiaoxiang hidden Source: http://www.cnblogs.com/kerrycode/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.