如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
当你在你想要更改密码的系统上使用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.
其他回答
这就是我的解决方案。我在Ubuntu 18.04工作: https://stackoverflow.com/a/46076838/2400373
但是重要的是最后一步的改变:
UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
对于Ubuntu 18.04和mysql版本14.14,Distrib 5.7.22,请按照以下步骤重置mysql密码。
步骤1
sudo systemctl stop mysql
步骤2
sudo systemctl edit mysql
这个命令将在nano编辑器中打开一个新文件,您将使用该文件编辑MySQL的服务覆盖。这些更改MySQL的默认服务参数。该文件将为空,因此添加以下内容:
[Service]
ExecStart=
ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid --skip-grant-tables --skip-networking
步骤3
sudo systemctl daemon-reload
sudo systemctl start mysql
步骤4
sudo mysql -u root
步骤5
FLUSH PRIVILEGES;
步骤6
UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHEREuser = 'root';
步骤7
UPDATE mysql.user SET plugin ='mysql_native_password' WHERE user = 'root';
步骤8
sudo systemctl revert mysql
最后
sudo systemctl restart mysql
现在享受
我分享一步一步的最终解决方案,重置MySQL密码在Linux Ubuntu。
参考来自博客(dbrnd.com)
步骤1: 停止MySQL服务。
sudo stop mysql
步骤2: 关闭所有运行mysqld。
sudo killall -9 mysqld
步骤3: 以安全模式启动mysqld。
sudo mysqld_safe --skip-grant-tables --skip-networking &
步骤4: 启动mysql客户端
mysql -u root
步骤5: 登录成功后,如果需要修改密码,请执行该命令。
FLUSH PRIVILEGES;
步骤6: 您可以更新mysql root密码。
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
注意:在MySQL 5.7中,Password列被称为authentication_string。
第七步: 请执行该命令。
FLUSH PRIVILEGES;
对我有用的(Ubuntu 16.04, mysql 5.7):
停止MySQL
sudo service mysql stop
制作MySQL服务目录。
sudo mkdir /var/run/mysqld
赋予MySQL用户写入服务目录的权限。
sudo chown mysql: /var/run/mysqld
手动启动MySQL,不需要权限检查或联网。
sudo mysqld_safe --skip-grant-tables --skip-networking &
在另一个控制台,无需密码登录。
mysql -uroot mysql
然后:
UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
EXIT;
关闭MySQL。
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
正常启动MySQL服务。
sudo service mysql start
如果你想修改MySQL root密码,在终端输入:
Sudo dpkg-reconfigure mysql-server-5.5
MySQL守护进程将被停止,并提示您输入新密码。