如何重设或更改MySQL root密码? [英] How to reset or change the MySQL root password?
问题描述
如何更改ubuntu服务器中的MySQL根密码和用户名?设置任何更改之前,我需要停止mysql服务吗?
How do I change the MySQL root password and username in ubuntu server? Do I need to stop the mysql service before setting any changes?
我也有phpmyadmin设置,phpmyadmin会自动更新吗?
I have a phpmyadmin setup as well, will phpmyadmin get updated automatically?
推荐答案
在Ubuntu Linux上设置/更改/重置MySQL根密码.在终端中输入以下行.
Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.
- 停止MySQL服务器:
sudo /etc/init.d/mysql stop
-
启动
mysqld
配置:sudo mysqld --skip-grant-tables &
- Stop the MySQL Server:
sudo /etc/init.d/mysql stop
Start the
mysqld
configuration:sudo mysqld --skip-grant-tables &
在某些情况下,您必须先创建/var/run/mysqld
:
In some cases, you've to create the /var/run/mysqld
first:
sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld
sudo service mysql start
mysql -u root mysql
用新密码替换YOURNEWPASSWORD
:
sudo service mysql start
mysql -u root mysql
Replace YOURNEWPASSWORD
with your new password:
UPDATE
mysql.user
SET
Password = PASSWORD('YOURNEWPASSWORD')
WHERE
User = 'root';
FLUSH PRIVILEGES;
exit;
注意:在某些版本中,如果
password
列不存在,则可能要尝试:
UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';
Note: on some versions, if
password
column doesn't exist, you may want to try:
UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';
注意:此方法不被认为是重置密码的最安全方法,但是它可以起作用.
参考文献:
- Set / Change / Reset the MySQL root password on Ubuntu Linux
- How to Reset the Root Password
这篇关于如何重设或更改MySQL root密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!