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

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


当前回答

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的PASSWORD()时,它可能会导致密码在MySQL日志中以cleartext [source]显示。对我来说,让它们和备份等像密码一样安全听起来像是噩梦,所以我喜欢这样做:

On your local machine, run this with your password: mysql -u someuser -p < <(echo "SELECT PASSWORD('mypass');") Note the space in front to prevent it from turning up in the bash history (for other distros than Ubuntu, this might work differently – source). On your server machine, execute the following command to change its MySQL root password (replace myhash with your password's hash as printed by the first command): mysql -u root -p < <(echo "SET PASSWORD FOR root@localhost = 'myhash';") Optionally, let's be a bit paranoid: On your local machine, clear your terminal screen with clear and purge your virtual terminal scrollback, to hide the cleartext password appearing in the command above.

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

关于这个话题的大多数答案都过时了;在写这个答案之前,MySQL发生了两个主要的变化:

1-用户表中的“Password”字段已被“authentication_string”列取代。

2-“Password”加密功能:Password(“of some text”)已弃用。

更多信息请参考此链接:dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

下面的步骤对我很有效。我使用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 -u root -p

然后按照mysql>提示修改当前用户的密码:

mysql> set password=password('the_new_password');
mysql> flush privileges;