I just installed MySQL on Ubuntu and the root user can't log in :)
我刚在Ubuntu上安装了MySQL, root用户无法登录:)
How can I recover or find out my password? Using blank for password does not work.
如何找回或找出我的密码?为密码使用空格是无效的。
8 个解决方案
#1
122
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):
您可以通过使用—skip-grant表运行服务器,并以root(或使用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
Now you should be able to login as root with your new password.
现在,您应该可以使用新密码以root身份登录了。
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.
还可以找到在/home/$USER/中重置密码的查询。mysql_history或/root/.重新设置密码的用户的mysql_history,但上面的内容总是有效的。
Note: prior to MySQL 5.7 the column was called password
instead of authentication_string
. Replace the line above with
注意:在MySQL 5.7之前,列被称为password而不是authentication_string。将上面的线替换为
mysql> update user set password=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';
#2
17
I realize that this is an old thread, but I thought I'd update it with my results.
我意识到这是一个旧的线程,但是我想用我的结果更新它。
Alex, it sounds like you installed MySQL server via the meta-package 'mysql-server'. This installs the latest package by reference (in my case, mysql-server-5.5). I, like you, was not prompted for a MySQL password upon setup as I had expected. I suppose there are two answers:
Alex,听起来好像你是通过元包的MySQL -server来安装MySQL服务器的。它通过引用安装最新的包(在我的例子中是mysql-server-5.5)。我和您一样,在安装时没有像我预期的那样提示输入MySQL密码。我想有两个答案:
Solution #1: install MySQL by it's full name:
解决方案#1:用它的全名安装MySQL:
$ sudo apt-get install mysql-server-5.5
Or
或
Solution #2: reconfigure the package...
解决方案#2:重新配置包…
$ sudo dpkg-reconfigure mysql-server-5.5
You must specific the full package name. Using the meta-package 'mysql-server' did not have the desired result for me. I hope this helps someone :)
您必须指定完整的包名。使用元包'mysql-server'并没有得到想要的结果。我希望这能帮助到某人:)
Reference: https://help.ubuntu.com/12.04/serverguide/mysql.html
参考:https://help.ubuntu.com/12.04/serverguide/mysql.html
#3
6
MySQL 5.5 on Ubuntu 14.04 required slightly different commands as recommended here. In a nutshell:
在Ubuntu 14.04上,MySQL 5.5要求使用稍微不同的命令。简而言之:
sudo /etc/init.d/mysql stop
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
And then from the MySQL prompt
然后从MySQL提示符
FLUSH PRIVILEGES;
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;
And the cited source offers an alternate method as well.
引用的来源也提供了另一种方法。
#4
3
For RHEL-mysql 5.5:
RHEL-mysql 5.5:
/etc/init.d/mysql stop
/etc/init.d/mysql start --skip-grant-tables
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
mysql -uroot -pnewpwd
mysql>
#5
1
You can't - however : http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
但是,您不能:http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
#6
1
Hmm Mysql 5.7.13 to reset all I did was:
恩,Mysql 5.7.13重置我所做的是:
$ sudo service mysql stop
To stop mysql
$ sudo服务停止mysql
$ mysqld_safe --skip-grant-tables &
Start mysql
$ mysqld_safe——skip-grant-tables &启动mysql
$ mysql -u root
美元mysql - u根
Just like the correct answer. Then all I did was do what @eebbesen did.
就像正确的答案一样。然后我所做的就是做@eebbesen做的事。
mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('NEW-password-HERE');
mysql>设置root@'localhost' =密码('NEW-password-HERE');
Hope it helps anyone out there :)
希望它能帮助任何人:
#7
0
Under MYSQL 5.7, If you are using mysql for development purpose, just :
在MYSQL 5.7下,如果您使用MYSQL进行开发,只需:
1.kill mysql :
1。杀死mysql:
$ sudo service mysql stop
2.start mysql under --skip-grant-tables mode:
2。在—skip-grant-tables模式下启动mysql:
$ sudo mysqld_safe --skip-grant-tables
and, further, you could try to change the user table under "skip-grant-table" mode, however I failed.
而且,您还可以尝试在“skip-grant-table”模式下更改用户表,但是我失败了。
so, this is just a workaround.
这只是一个变通方法。
#8
0
sudo mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD_HERE';
FLUSH PRIVILEGES;
mysql -u root -p # and it works
#1
122
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):
您可以通过使用—skip-grant表运行服务器,并以root(或使用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
Now you should be able to login as root with your new password.
现在,您应该可以使用新密码以root身份登录了。
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.
还可以找到在/home/$USER/中重置密码的查询。mysql_history或/root/.重新设置密码的用户的mysql_history,但上面的内容总是有效的。
Note: prior to MySQL 5.7 the column was called password
instead of authentication_string
. Replace the line above with
注意:在MySQL 5.7之前,列被称为password而不是authentication_string。将上面的线替换为
mysql> update user set password=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';
#2
17
I realize that this is an old thread, but I thought I'd update it with my results.
我意识到这是一个旧的线程,但是我想用我的结果更新它。
Alex, it sounds like you installed MySQL server via the meta-package 'mysql-server'. This installs the latest package by reference (in my case, mysql-server-5.5). I, like you, was not prompted for a MySQL password upon setup as I had expected. I suppose there are two answers:
Alex,听起来好像你是通过元包的MySQL -server来安装MySQL服务器的。它通过引用安装最新的包(在我的例子中是mysql-server-5.5)。我和您一样,在安装时没有像我预期的那样提示输入MySQL密码。我想有两个答案:
Solution #1: install MySQL by it's full name:
解决方案#1:用它的全名安装MySQL:
$ sudo apt-get install mysql-server-5.5
Or
或
Solution #2: reconfigure the package...
解决方案#2:重新配置包…
$ sudo dpkg-reconfigure mysql-server-5.5
You must specific the full package name. Using the meta-package 'mysql-server' did not have the desired result for me. I hope this helps someone :)
您必须指定完整的包名。使用元包'mysql-server'并没有得到想要的结果。我希望这能帮助到某人:)
Reference: https://help.ubuntu.com/12.04/serverguide/mysql.html
参考:https://help.ubuntu.com/12.04/serverguide/mysql.html
#3
6
MySQL 5.5 on Ubuntu 14.04 required slightly different commands as recommended here. In a nutshell:
在Ubuntu 14.04上,MySQL 5.5要求使用稍微不同的命令。简而言之:
sudo /etc/init.d/mysql stop
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root
And then from the MySQL prompt
然后从MySQL提示符
FLUSH PRIVILEGES;
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;
And the cited source offers an alternate method as well.
引用的来源也提供了另一种方法。
#4
3
For RHEL-mysql 5.5:
RHEL-mysql 5.5:
/etc/init.d/mysql stop
/etc/init.d/mysql start --skip-grant-tables
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
mysql -uroot -pnewpwd
mysql>
#5
1
You can't - however : http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
但是,您不能:http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
#6
1
Hmm Mysql 5.7.13 to reset all I did was:
恩,Mysql 5.7.13重置我所做的是:
$ sudo service mysql stop
To stop mysql
$ sudo服务停止mysql
$ mysqld_safe --skip-grant-tables &
Start mysql
$ mysqld_safe——skip-grant-tables &启动mysql
$ mysql -u root
美元mysql - u根
Just like the correct answer. Then all I did was do what @eebbesen did.
就像正确的答案一样。然后我所做的就是做@eebbesen做的事。
mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('NEW-password-HERE');
mysql>设置root@'localhost' =密码('NEW-password-HERE');
Hope it helps anyone out there :)
希望它能帮助任何人:
#7
0
Under MYSQL 5.7, If you are using mysql for development purpose, just :
在MYSQL 5.7下,如果您使用MYSQL进行开发,只需:
1.kill mysql :
1。杀死mysql:
$ sudo service mysql stop
2.start mysql under --skip-grant-tables mode:
2。在—skip-grant-tables模式下启动mysql:
$ sudo mysqld_safe --skip-grant-tables
and, further, you could try to change the user table under "skip-grant-table" mode, however I failed.
而且,您还可以尝试在“skip-grant-table”模式下更改用户表,但是我失败了。
so, this is just a workaround.
这只是一个变通方法。
#8
0
sudo mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD_HERE';
FLUSH PRIVILEGES;
mysql -u root -p # and it works