Linux MySQL 5.7:error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

Source: Internet
Author: User

Environment: mac10.12

Source: http://www.cnblogs.com/kerrycode/p/3861719.html

Error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using password:no) errors encountered using root login. As shown below

[[email protected] tmp]
                Preparing ... ########################################### [100%]
   1:mysql-server           ########################################### [100%]
[[email protected] tmp]
-bash:rmp:command not found
[[email protected] tmp]
                Preparing ... ########################################### [100%]
   1:mysql-client           ########################################### [100%]
[[email protected] tmp] #/etc/rc.d/init.d/mysql Status
MySQL is not running[failed]
[[email protected] tmp] #/etc/rc.d/init.d/mysql Start
Starting MySQL. [  OK  ]
[[email protected] tmp] # mysql-u Root-p
' Root ' @' localhost ' (using Password:no)
[[email protected] tmp] # mysql-u Root MySQL
' Root ' @' localhost ' (using Password:no)

Installation process has not set the root password, not clear the root password, search for some information on the Internet, there are some situations:

1: Some blogs say that Root's random password is in/root/.mysql_secret, but I don't have/root/.mysql_secret file in this version at all. Search for an article that has the following effect (no confirmation). It is not clear to me why this version did not generate this file?

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no): Indicates a temporary password without generating root

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes): Represents a temporary password for root generation.

2: Some sources say Root's default password is empty, after confirming that it is old version, Mysql 5.6 and later release is in security consideration, root password is not empty.

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

Workaround:

First stop the MySQL server

[[email protected] INIT.D] #/etc/rc.d/init.d/mysql Stop
Shutting down MySQL. [OK]

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

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

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

[[email protected] INIT.D] # Mysqld_safe--user=mysql--skip-grant-tables--skip-networking &
[2] 9396
[[email protected] 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 appear unresponsive state, need to use CTRL + C to interrupt the session, check the/var/lib/mysql/db-server.err log, and found no other exception information. Did not figure out why the session window would appear unresponsive.

Tail-200/var/lib/mysql/db-server.err | More
' 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 the DEFAULT value is deprecated. Please use--explicit_defaults_for_timesta
For more details).
' 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) is active.
For purge to start
2014-07-22 14:59:47 9516 [Note] innodb:5.6.19 started; Log sequence Number 1626087
for connections.
' 5.6.19 '  /var/lib/mysql/mysql.sock '  port:0  mysql Community Server (GPL)

[[email protected] INIT.D] # mysql-u Root MySQL
For completion of table and column names
Can turn off this feature to get a quicker startup with-a
Welcome to the MySQL Monitor.  end with; or \g.
Your MySQL Connection ID is 1
Server version:5.6.19 MySQL Community Server (GPL)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
' \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                |
+-----------+------+-------------------------------------------+------------------+
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 up the user or changing the password, flush privileges will be required to flush the MySQL system permission related tables, otherwise access is denied, and another way is to restart the MySQL server for the new settings to take effect.

mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Mysql> quit
Bye
[[email protected] 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
[[email protected] INIT.D] # mysql-u Root P
' Root ' @' localhost ' (using Password:no)
[[email protected] INIT.D] # mysql-u Root-p
Welcome to the MySQL Monitor.  end with; or \g.
Your MySQL Connection ID is 2
Server version:5.6.19
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
' \c ' to clear the current input statement.

In addition, if you log in to the MySQL database after executing the script encounter ERROR 1820 (HY000): You must set PASSWORD before executing this statement, can be used to reset the password to solve the problem.

mysql>Set Password = password (  

At this point the problem is solved, but there are a lot of doubts, why this error? In fact, so much information is only to say the solution, but all avoided the cause of the problem.

Linux MySQL 5.7:error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

Related Article

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.