如何修改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';
详情请点击这里。
其他回答
重置或修改密码请输入sudo dpkg-reconfigure mysql-server-X。X (X.X是mysql版本你已经安装,即5.6,5.7),然后你会提示一个屏幕,你必须设置新密码,然后在下一步确认密码,只是等待一会儿。就是这样。
当你在你想要更改密码的系统上使用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.
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密码时,上面列出的以下命令没有帮助。我发现进入终端并使用这些命令是毫无意义的。相反,使用命令sudo停止一切。如果有帮助的话,删除windows的system32。
您可以使用该命令:
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
之后请冲洗:
FLUSH PRIVILEGES;