如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?

我有一个phpmyadmin设置以及,phpmyadmin会自动更新?


当前回答

下面的步骤对我很有效。我使用MySQL 8。*在Ubuntu上

停止MySQL服务,检查状态确认服务已停止

Sudo systemctl停止mysql Sudo systemctl status mysql

编辑systemd配置文件,这样您就可以在没有权限检查的情况下访问MySQL Sudo systemctl编辑mysql 复制并粘贴以下3行

(服务) ExecStart = ExecStart=/usr/sbin/mysqld——skip-grant-tables——skip-networking

粘贴行后按CTRL+0保存,然后按CTRL+X退出

重新加载mysql服务并启动它(使用——skip-grant-table启动服务)

Sudo systemctl daemon-reload Sudo systemctl启动mysql

5.现在无需密码即可连接MySQL服务器

sudo mysql -u root

6.通过运行加载授权表

mysql> FLUSH PRIVILEGES;

重置root密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPasswordHere';

关闭mysql连接

mysql >退出

恢复对mysql systemd文件所做的修改

Sudo systemctl恢复mysql

重新加载mysql守护进程以进行更改。

Sudo systemctl daemon-reload

最后重新启动MySQL服务

Sudo systemctl restart mysql

现在用第7步设置的新密码连接mysql

你可以访问这个链接重置mysql 8的根密码了解更多细节。

其他回答

当更改/重置MySQL密码时,上面列出的以下命令没有帮助。我发现进入终端并使用这些命令是毫无意义的。相反,使用命令sudo停止一切。如果有帮助的话,删除windows的system32。

你可以尝试以下步骤来重置mysql的root密码:

首先停止Mysql服务

sudo /etc/init.d/mysql stop 

以root用户登录,不需要密码 Sudo mysqld_safe—skip-grant-tables &

登录mysql终端后,你需要执行更多的命令:

use mysql;




UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';


flush privileges;


sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown

重启mysql服务器后 如果你仍然面临错误,你必须访问: 重置MySQL的root密码

Instead of resetting the password there is a work around on the local machine if you have setup phpmyadmin to connect without giving the password or username. Check this out by starting mysql, apache etc. I have xampp installed in my local machine. So starting the xampp will start all the necessary services. Now going to http://localhost/phpmyadmin shows me all the databases. This confirms that you have saved the username and passsword in the config file of phpmyadmin which can be found in the phpmyadmin install location. If you have xampp installed the phpmyadmin folder can be found in the root folder of xampp installation. Search for the word password in the config.inc.php file. There you will find the password and username.

设置MySQL密码

停止MySQL数据库服务

sudo /etc/init.d/mysql stop

创建一个新的mysqld目录

Sudo mkdir /var/run/mysqld/

给予mysql用户访问权限

Sudo chown mysql /var/run/mysqld/

以安全模式启动MySQL…

Sudo mysqld_safe—skip-grant-tables &

无需密码登录数据库服务器

Sudo mysql -u root

使用默认的mysql数据库

使用mysql;

修改root密码

update user set authentication_string=PASSWORD(" new_passwor_here ") where user ='root';

保存更改 冲洗特权; 退出; 停止MySQL安全模式,启动MySQL默认服务

sudo /etc/init.d/mysql stop

sudo /etc/init.d/mysql start

使用root新密码重新登录MySQL数据库

-u root -p

***来源:https://websiteforstudents.com/resetting-mysql-root-password-on-ubuntu-16-04-17-10-and-18-04-lts/

官方和简单的方法来重置根密码在ubuntu服务器…

如果你在16.04 14.04 12.04

sudo dpkg-reconfigure mysql-server-5.5

如果你在10.04:

sudo dpkg-reconfigure mysql-server-5.1

如果您不确定安装了哪个mysql-server版本,您可以尝试:

dpkg --get-selections | grep mysql-server

mysql-server-5.7的更新说明

请注意,如果您使用的是mysql-server-5.7,则不能使用上面所示的更简单的dpkg-reconfigure方法。

如果你知道密码,登录并运行这个:

UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE USER='root';
FLUSH PRIVILEGES;

或者,您可以使用以下方法:

sudo mysql_secure_installation

这将询问您一系列关于保护安装的问题(强烈推荐),包括是否需要提供新的根密码。

如果你不知道root密码,请参考这个以ubuntu为中心的进程写上去。

查看更多信息:

https://help.ubuntu.com/16.04/serverguide/mysql.html https://help.ubuntu.com/14.04/serverguide/mysql.html