MySQL 错误 1045 (28000):用户“root”@“localhost”的访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46792376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'
提问by Abhishek Jain
While connecting to mysql through 'root' user, I am getting the mentioned error. Commands tried:
通过“root”用户连接到 mysql 时,出现上述错误。尝试的命令:
mysql (as by default it takes root user)
mysql -u root -p
I Tried putting the root credentials in "/etc/my.cnf" file, but no luck.
我尝试将根凭据放在“/etc/my.cnf”文件中,但没有运气。
Please help.
请帮忙。
回答by SHEESHRAM
Note: All credit to this answer goes to Netajiand you can found his answer Here
注意:此答案的所有功劳都归功于Netaji,您可以在此处找到他的答案
my problem was solved in below way.
我的问题是通过以下方式解决的。
When I was entered below command then I will get an error. sudo mysql -u root -p
当我在命令下面输入时,我会收到一个错误。须藤mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).
To resolve this follow below steps.
要解决此问题,请按照以下步骤操作。
enter command
sudo mysqld_safe --skip-grant-tables & [4] 21878
输入命令
须藤 mysqld_safe --skip-grant-tables & [4] 21878
Then the below error occurred.
然后出现了下面的错误。
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
To resolve this error, then follow below lines.
要解决此错误,请按照以下几行操作。
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.
then MySQL prompt will appear. then after set your password.
然后会出现 MySQL 提示。然后在设置密码后。
vi) FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
vi) systemctl stop mysql
vi) After that loing in below way.
vi) 在下面的方式之后。
`mysql -u root -p`
回答by Gar
You have to reset your mysql root password
你必须重置你的mysql root密码
please follow these instructions : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
请按照以下说明操作:https: //dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
回答by iamnoten
IMHO, you didn't describe you situation clearly. Is your mysql a new install, reinstall or upgrade? Or any operation you performed on root user? What is your mysql version? ...
恕我直言,你没有清楚地描述你的情况。您的 mysql 是全新安装、重新安装还是升级?或者您对root用户执行的任何操作?你的mysql版本是多少?...
Actually, there are many questions similar to your cases, have your tired their solution?
其实和你的案例有很多类似的问题,你厌倦了他们的解决方案吗?
回答by ansi_lumen
First: You don't want to put your credentials in /etc/my.cnf
but in ~/.my.cnf
(mind the leading dot). The contents of .my.cnf
should look like this
第一:你不想把你的凭据放在里面,/etc/my.cnf
而是放在~/.my.cnf
(注意前导点)。的内容.my.cnf
应该是这样的
[client]
user=USERNAME
pass=PASSWORD
If your password is correct, you should be able to login with just mysql
without any options.
如果您的密码正确,您应该可以在mysql
没有任何选项的情况下登录。
If that doesn't work and you are not able to login with
如果这不起作用并且您无法登录
mysql -u root -pMYPASS
(mind the missing space between -p
and the actual password), then you may have to reset the password.
(注意-p
和实际密码之间缺少空格),那么您可能需要重置密码。