ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)

Source: Internet
Author: User
Tags flush new set

Today began to learn MySQL, so first installed MySQL 5.6.19 64bit version of the database, the result of the installation was successful, but the use of root login encountered error 1045 (28000): Access denied for user ' root ' @ ' LocalHost ' (using Password:no) error. As shown below

                Preparing ... ########################################### [100%]
   1:mysql-server           ########################################### [100%]
-bash:rmp:command not found
                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
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 installation process did not set the root password, do not know the root password, search for some information on the web, there are roughly the following conditions:

1: Some bloggers say that Root's random password is in/root/.mysql_secret, but I don't have/root/.mysql_secret files in this version at all. Search for an article to the effect below (no confirmation). I do not understand why this version does not generate this file at this time.

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using password:no): temporary password that does not generate root

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes): Indicates that a temporary password was generated for root.

2: Some information that the root of the default password is empty, confirmed that the previous version, Mysql 5.6 and later version out of security considerations, the root password is not empty.

In addition, I found in the official website forum Many people have encountered similar problems error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

Workaround:

First of all, shut down the MySQL server

[Root@db-server init.d]#/etc/rc.d/init.d/mysql Stop
Shutting down MySQL. [OK]

Then use the Mysqld_safe command to start MySQL and update the password for the root account

--skip-grant-tables: Do not start grant-tables (authorization table), skip permission control.

--skip-networking: Skip TCP/IP protocol, only on native access (from some data on the Web, this option is not required.) Can not be used)

[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 appears unresponsive, requires CTRL + C to interrupt the session, checks the/var/lib/mysql/db-server.err log, and finds no other exception information. Did not understand why the session window appears 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 (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 the 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)

[Root@db-server init.d]# mysql-u root MySQL
Reading table information for completion of table and column names
You can turn off the feature to get a quicker startup with-a
Welcome to the MySQL Monitor.  Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.6.19 MySQL Community Server (GPL)
Copyright (c), 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may trademarks of their respective
Owners.
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql> Select Host, User, password,password_expired
    -> 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

New set user or change password need flush privileges Refresh MySQL system permissions related table, otherwise there will be denied access, there is another way, is to restart the MySQL server, to make the new settings take effect.

mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

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.