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

Source: Internet
Author: User
Tags mysql command line

[[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 be sure is that the MySQL command line SQL command keyword is not differentiated between uppercase and lowercase. In MySQL 5.1.51 version number;

2. Stop the normal startup mysqld first.

3. How to bypass the root password check? start mysqld;

4. Query the user table and find that the user table is empty. Insert a root user, turn off mysqld, start mysqld Normally, use the root user, the new password Newpass will be able to log into the MySQL shell

?

Here's how to resolve the pass:

1. Start the normal mysqld stop off

[[Email protected] ~]# service mysqld stop
Stopping mysqld:?????????????????????????????????????????? [? Ok? ]

2. How to bypass root password check? Start MySQL server and let it execute in the background;

[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. Update the password of the root user in the users table in accordance with the method left by the predecessor. Results found 0 rows affected. Then select to look at 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????????????????????? |
+---------------------------+
All 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. See a root user;

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 password of the root user. 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 the MySQL service to start MySQL server,mysql-u root-p again in normal way? The password is newpass.

[[email protected] ~]# service mysqld stop
141215 16:12:24 mysqld_safe mysqld from PID file/var/run/mysqld/my Sqld.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 ' roo T ' @ ' 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 '

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.