簡體   English   中英

錯誤1044(42000):用戶'@'localhost'對數據庫'mysql'的訪問被拒絕

[英]ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

我知道這個問題已經問過很多遍了,我讀了很多與此有關的問題,但是我認為我是不同的。

我使用版本10.10.3的Mac和終端機來執行命令。

我試圖創建一個本地數據庫(並且我之前做過),但是由於某種原因,訪問被不斷拒絕。

這是我的終端的樣子:

iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -v
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 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.

Reading history-file /Users/639/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit;
Writing history-file /Users/639/.mysql_history
Bye
iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.24 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> create database wordpress_db;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'wordpress_db'

如您所見,我可以登錄mysql,但沒有創建數據庫的權限。

我嘗試以以下方式登錄:

$ /usr/local/mysql/bin/mysql -u root

和:

$ /usr/local/mysql/bin/mysql -u root -p

我沒有密碼,但沒有密碼也可以輸入mysql,但是無法創建數據庫。

選擇current_user(); 返回此:

mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| @localhost     |
+----------------+
1 row in set (0,00 sec)

嘗試使用--skip-grant-tables啟動mysql

mysqld --skip-grant-tables

然后使用mysql命令行連接到沒有用戶名/密碼的mysqld

shell> mysql

然后發出命令

> mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
>        WHERE User='root'; mysql> FLUSH PRIVILEGES;

首先,嘗試以下命令:

sudo dpkg-reconfigure mysql-server-5.5

但是將5.5替換為當前的mysql服務器版本,系統將要求您輸入新的root密碼。

如果這樣不起作用,請嘗試使用手冊中的這些說明

我遇到過同樣的問題。 我要做的就是注銷外殼,然后使用mysql -u root -p再次登錄到我的mysql shell中。

然后將提示您輸入密碼。 由於設置時未使用密碼,因此按Enter鍵就可以了。

我希望這也對您有用:)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM