![](/img/trans.png)
[英]Mac mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'
[英]MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'
通過“root”用戶連接到 mysql 時,出現上述錯誤。 嘗試的命令:
mysql (as by default it takes root user)
mysql -u root -p
我嘗試將根憑據放在“/etc/my.cnf”文件中,但沒有運氣。
請幫忙。
注意:此答案的所有功勞都歸功於Netaji ,您可以在此處找到他的答案
我的問題是通過以下方式解決的。
當我在命令下面輸入時,我會收到一個錯誤。 須藤mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).
要解決此問題,請按照以下步驟操作。
輸入命令
須藤 mysqld_safe --skip-grant-tables & [4] 21878
然后出現了下面的錯誤。
2018-12-17T06:43:33.106111Z mysqld_safe Logging to syslog.
2018-12-17T06:43:33.108971Z mysqld_safe Logging to '/var/log/mysql/error.log'.
/usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
2018-12-17T06:43:33.111388Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
/usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql//error.log: Permission denied
^C
[4] Exit 1 mysqld_safe --skip-grant-tables
要解決此錯誤,請按照以下幾行操作。
i) systemctl stop mysql
2018-12-17T06:48:42.971692Z mysqld_safe Logging to syslog.
2018-12-17T06:48:42.974451Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-12-17T06:48:42.976653Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
ii) sudo mkdir -p /var/run/mysqld
iii) sudo chown mysql:mysql /var/run/mysqld
iv)sudo mysqld_safe --skip-grant-tables &
[5] 24203
2018-12-17T06:50:39.135292Z mysqld_safe Logging to syslog.
2018-12-17T06:50:39.137938Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-12-17T06:50:39.152966Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
v) Then connect mysql -u root.
然后會出現 MySQL 提示。 然后在設置密碼后。
vi) FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
vi) systemctl stop mysql
vi) 在下面的方式之后。
`mysql -u root -p`
你必須重置你的mysql root密碼
請按照以下說明操作: https : //dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
恕我直言,你沒有清楚地描述你的情況。 您的 mysql 是全新安裝、重新安裝還是升級? 或者您對root用戶執行的任何操作? 你的mysql版本是多少? ...
其實和你的案例有很多類似的問題,你厭倦了他們的解決方案嗎?
首先:您不想將您的憑據放在/etc/my.cnf
而是在~/.my.cnf
(注意前導點)。 .my.cnf
的內容應該是這樣的
[client]
user=USERNAME
pass=PASSWORD
如果您的密碼正確,您應該可以只使用mysql
登錄而無需任何選項。
如果這不起作用並且您無法登錄
mysql -u root -pMYPASS
(注意-p
和實際密碼之間缺少空格),那么您可能需要重置密碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.