mysql 安裝完成後登陸不了mysql的 shell 即mysql>遇到:ERROR 1045 (28000): Access denied for user 'root'@'localhost‘

來源:互聯網
上載者:User

標籤:mysql   登入出錯   

[[email protected] ~]# mysql
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

遇到:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

網上找了很多的文章還是沒有解決我的問題;

1.首先可以確認的是mysql 命令列 sql命令關鍵字是不區分大小寫;在5.1.51版本;

2.先將正常啟動的mysqld stop掉;

3.再以繞過root口令檢查的方式 start mysqld;

 

以下是解決經過:

1.先將正常啟動的mysqld stop掉

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

2.用繞過root口令檢查的方式 啟動 mysql 伺服器,並且讓其在後頭運行;

[[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斷行符號,進入mysql shell,按照前人留下的方法, update user表中的 root 使用者的密碼,結果發現 0 rows affected,再select 細看是 user 表是空的;

[[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                      |
+---------------------------+
23 rows in set (0.00 sec)

mysql> select * from user;
Empty set (0.00 sec)

4.在user表 insert 一個名稱為root的使用者; 

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 再更新 root 使用者的密碼,也能返回成功了;


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 剛才的 mysql服務,以正常方式重新啟動mysql 伺服器,mysql -u root -p  密碼是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) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are 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>

 

mysql 安裝完成後登陸不了mysql的 shell 即mysql>遇到:ERROR 1045 (28000): Access denied for user 'root'@'localhost‘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.