2015-10-26 95 views
-1

我在CentOS中使用sudo yum install mysql-server安裝了MySQL,並使用mysql -u root -p登錄到MySQL並給出空白密碼。它不允許我使用MySQL數據庫或選擇用戶/更新密碼/創建數據庫。MySQL CentOS:拒絕用戶'@'localhost'到數據庫的訪問

mysql> select user(); 
+----------------+ 
| user()   | 
+----------------+ 
| [email protected] | 
+----------------+ 
1 row in set (0.00 sec) 

mysql> use mysql; 
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 

mysql> UPDATE user SET Password=PASSWORD('*****') WHERE user='root'; 
ERROR 1046 (3D000): No database selected 

mysql> show grants; 
+--------------------------------------+ 
| Grants for @localhost    | 
+--------------------------------------+ 
| GRANT USAGE ON *.* TO ''@'localhost' | 
+--------------------------------------+ 
1 row in set (0.00 sec) 


[[email protected]****~]$ sudo /sbin/service mysqld stop 
Redirecting to /bin/systemctl stop mysqld.service 
[[email protected]****~]$ sudo mysqld_safe 
151026 14:40:32 mysqld_safe Logging to '/var/log/mysqld.log'. 
151026 14:40:32 mysqld_safe A mysqld process already exists 
[[email protected]*****~]$ mysql -u root 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 152 
Server version: 5.6.27 MySQL Community Server (GPL) 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. 

Oracle is a registered trademark of Oracle Corporation and/or its 
affiliates. Other names may be trademarks of their respective 
owners. 

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

mysql> use mysql; 
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 
mysql> 

錯誤再次:

[[email protected]~]$ sudo /sbin/service mysqld stop 
Redirecting to /bin/systemctl stop mysqld.service 
[centos~]$ sudo mysqld_safe --skip-grant-tables & 
[1] 25678 
[centos~]$ 151026 14:53:07 mysqld_safe Logging to '/var/log/mysqld.log'. 
151026 14:53:07 mysqld_safe A mysqld process already exists 

[1]+ Exit 1     sudo mysqld_safe --skip-grant-tables 
[[email protected]~]$ sudo mysql -u root 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 160 
Server version: 5.6.27 MySQL Community Server (GPL) 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. 

Oracle is a registered trademark of Oracle Corporation and/or its 
affiliates. Other names may be trademarks of their respective 
owners. 

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

mysql> use mysql; 
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 

請讓我知道如何解決這個問題。

+0

啓動它,您不會手動更改用戶數據庫。 '爲root @ localhost = password('*****')設置密碼' –

+0

當我這樣做時,它會拋出一個錯誤。 mysql>爲root @ localhost = password('****')設置密碼; 錯誤1133(42000):在用戶表中找不到任何匹配的行 – CentosUser

回答

0
  1. sudo /etc/init.d/mysql stop
  2. sudo mysqld_safe --skip-grant-tables &
  3. sudo mysql -u root
  4. 安裝新的MySQL root用戶密碼

    use mysql; 
    update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root'; 
    flush privileges; 
    quit 
    
  5. 停止MySQL服務器:sudo /etc/init.d/mysql stop(如有錯誤使用sudo

  6. 啓動MySQL服務器並進行測試:sudo mysql -u root -p

+0

步驟1,2和3成功。但在第4步中,當我運行「使用MySQL」時,出現錯誤。 mysql>使用mysql; 錯誤1044(42000):訪問拒絕用戶'''本地主機'到數據庫'mysql' – CentosUser

+0

顯示我的第4個查詢 –

+0

mysql> use mysql; 錯誤1044(42000):訪問拒絕用戶'''本地主機'到數據庫'mysql' – CentosUser

0

如果沒有設置密碼,你不能給使用MySQL命令-p參數。只用mysql -u root

相關問題