如何找到我的MySQL根密码? [英] How do I find out my root MySQL password?
问题描述
我刚刚在Ubuntu上安装了MySQL,root用户无法登录:)
I just installed MySQL on Ubuntu and the root user can't log in :)
如何恢复或找出我的密码?使用空白输入密码不起作用.
How can I recover or find out my password? Using blank for password does not work.
推荐答案
您可以通过使用--skip-grant-tables
运行服务器来重置根密码,并通过以root身份(或使用sudo)运行以下命令来不使用密码登录:
You can reset the root password by running the server with --skip-grant-tables
and logging in without a password by running the following as root (or with sudo):
# service mysql stop
# mysqld_safe --skip-grant-tables &
$ mysql -u root
mysql> use mysql;
mysql> update user set authentication_string=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
# service mysql stop
# service mysql start
$ mysql -u root -p
现在,您应该可以使用新密码以root用户身份登录.
Now you should be able to login as root with your new password.
还可以在重设密码的用户的/home/$USER/.mysql_history
或/root/.mysql_history
中找到重设密码的查询,但是以上操作始终有效.
It is also possible to find the query that reset the password in /home/$USER/.mysql_history
or /root/.mysql_history
of the user who reset the password, but the above will always work.
注意:在MySQL 5.7之前,该列称为password
而不是authentication_string
.将上面的行替换为
Note: prior to MySQL 5.7 the column was called password
instead of authentication_string
. Replace the line above with
mysql> update user set password=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';
这篇关于如何找到我的MySQL根密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!