After MySQL installation is complete, the MySQL shell is mysql> encountered: ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost '

Source: Internet
Author: User

[[email protected] ~]# MySQL
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

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

On the internet to find a lot of articles or not solve my problem;

1. The first thing to confirm is that the MySQL command line SQL command keyword is case-insensitive; in the 5.1.51 version;

2. Start the normal mysqld stop off;

3. Start mysqld by bypassing the root password check;

Here's how to resolve the pass:

1. Start the normal mysqld stop off

[[Email protected] ~]# service mysqld stop
Stopping mysqld: [OK]

2. Start the MySQL server in a way that bypasses the root password check and let it run in the back;

[Email protected] ~]# mysqld_safe--user=mysql--skip-grant-tables--skip-networking &
[1] 25513
[Email protected] ~]# 141215 15:00:16 mysqld_safe Logging to '/var/log/mysqld.log '.
141215 15:00:16 Mysqld_safe starting mysqld daemon with databases From/var/lib/mysql

3. mysql Enter, enter the MySQL shell, according to the previous method, update the user table root password, the results found 0 rows affected, then select the user table is empty;

[[email protected] ~]# MySQL
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.1.51 Source Distribution

mysql> UPDATE user SET Password=password (' 123456 ') where user= ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows matched:0 changed:0 warnings:0

mysql> use MySQL
Database changed
Mysql> Show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| Columns_priv |
| db |
| Event |
| Func |
| General_log |
| Help_category |
| Help_keyword |
| help_relation |
| Help_topic |
| Host |
| Ndb_binlog_index |
| Plugin |
| Proc |
| Procs_priv |
| Servers |
| Slow_log |
| Tables_priv |
| Time_zone |
| Time_zone_leap_second |
| Time_zone_name |
| time_zone_transition |
| Time_zone_transition_type |
| user |
+---------------------------+
Rows in Set (0.00 sec)

Mysql> select * from user;
Empty Set (0.00 sec)

4. Insert a user who is named root in the user table;

mysql> INSERT INTO User (Host,user,password,select_priv,insert_priv) VALUES (' localhost ', ' root ', Password (' PASS3 ') , ' y ', ' y ');
Query OK, 1 row affected, 3 warnings (0.00 sec)

5. #看到有个root用户了;

Mysql> SELECT * from user
;
+-----------+------+-------------------------------------------+-------------+-------------+-------------+----- --------+-------------+-----------+-------------+---------------+--------------+-----------+------------+------ -----------+------------+------------+--------------+------------+-----------------------+------------------+-- ------------+-----------------+------------------+------------------+----------------+---------------------+--- -----------------+------------------+------------+--------------+----------+------------+-------------+-------- ------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Ssl_type | Ssl_cipher | X509_issuer | X509_subject | max_questions | Max_updates | max_connections | max_user_connections |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+----- --------+-------------+-----------+-------------+---------------+--------------+-----------+------------+------ -----------+------------+------------+--------------+------------+-----------------------+------------------+-- ------------+-----------------+------------------+------------------+----------------+---------------------+--- -----------------+------------------+------------+--------------+----------+------------+-------------+-------- ------+---------------+-------------+-----------------+----------------------+
| localhost | Root | *35B5E90BC4F5AE5D02ED515DF6B61141F24EDA02 | y           | y           | n           | n           | n           | n         | n           | n             | n            | n         | n          | n               | n          | n          | N            | n          | n                      | n                | n            | n               | n                | n                | n              | n                   | n                  | N                | n          | n            |           |            |              |               |             0 |            0 |                0 |                     0 |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+----- --------+-------------+-----------+-------------+---------------+--------------+-----------+------------+------ -----------+------------+------------+--------------+------------+-----------------------+------------------+-- ------------+-----------------+------------------+------------------+----------------+---------------------+--- -----------------+------------------+------------+--------------+----------+------------+-------------+-------- ------+---------------+-------------+-----------------+----------------------+
1 row in Set (0.00 sec)

6 re-update the root user password, can also return to success;


mysql> UPDATE user SET Password = Password (' newpass ') WHERE user = ' root ';
Query OK, 1 row Affected (0.00 sec)
Rows matched:1 changed:1 warnings:0

mysql> FLUSH privileges;
Query OK, 0 rows Affected (0.00 sec)

Mysql> exit

7.stop just MySQL service, restart MySQL server in normal way, mysql-u root-p password is newpass

[[Email protected] ~]# service mysqld stop
141215 16:12:24 mysqld_safe mysqld from PID File/var/run/mysqld/mysqld.pid ended
Stopping mysqld: [OK]
[1]+ done Mysqld_safe--user=mysql--skip-grant-tables--skip-networking
[[Email protected] ~]# service mysqld start
Starting mysqld: [OK]
[Email protected] ~]#
[[email protected] ~]# MySQL
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)
[Email protected] ~]# mysql-u root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 4
Server version:5.1.51 Source Distribution

Copyright (c), Oracle and/or its affiliates. All rights reserved.
This software comes with absolutely NO WARRANTY. This is the free software,
And you is welcome to modify and redistribute it under the GPL v2 license

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql>

After MySQL installation is complete, the MySQL shell is mysql> encountered: ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost '

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.