如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
该解决方案属于以前版本的MySQL。 通过使用套接字身份验证登录MySQL,您可以做到这一点。
sudo mysql -u root
然后可以运行以下命令。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
详情请点击这里。
其他回答
对于mysql 5.6,这个命令有效,你可以通过向导设置密码:
sudo dpkg-reconfigure mysql-server-5.6
官方和简单的方法来重置根密码在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
如果你知道“root”用户密码,请使用该凭证登录mysql。然后执行以下查询以更新密码。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_passowrd';
我还没有看到MySQL 8.0指南中推荐的官方步骤,这是唯一适合我的步骤。下面是这些步骤的总结。
Stop the MySQL server if it is running. Look in /var/lib/mysql/, /var/run/mysqld/, or /usr/local/mysql/data/ to find the pid file with the server's process ID. Generally the file begins with either mysqld or your system's host name and ends with .pid. Replace mysql-data-directory and host_name that you just found, in the following command: $ sudo kill `sudo cat /mysql-data-directory/host_name.pid` This command will create a text file in /tmp/mysql-init with the SQL statement and makes the mysql user the owner. Replace in the command MyNewPass with your own password. $ echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';" > /tmp/mysql-init && sudo chown mysql /tmp/mysql-init Start the MySQL server by running the following command on the command line. After this the password is updated and you can close the server again with CTRL+C. $ sudo mysqld --user=mysql --init-file=/tmp/mysql-init & Remove the temporary file with your password: $ sudo rm /tmp/mysql-init
当更改/重置MySQL密码时,上面列出的以下命令没有帮助。我发现进入终端并使用这些命令是毫无意义的。相反,使用命令sudo停止一切。如果有帮助的话,删除windows的system32。