如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
正如mysql文档中password()函数所说:
此函数在MySQL 8.0.11中被移除。
这将使mysql v8.0.11及更新版本的所有现有答案都失效。
根据mysql文档,重置root密码的新通用方法如下:
The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure): Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, if the server is started with the --skip-grant-tables option, it enables --skip-networking automatically to prevent remote connections. Connect to the MySQL server using the mysql client; no password is necessary because the server was started with --skip-grant-tables: shell> mysql In the mysql client, tell the server to reload the grant tables so that account-management statements work: mysql> FLUSH PRIVILEGES; Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use. To change the password for a root account with a different host name part, modify the instructions to use that host name. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables and --skip-networking options).
其他回答
当更改/重置MySQL密码时,上面列出的以下命令没有帮助。我发现进入终端并使用这些命令是毫无意义的。相反,使用命令sudo停止一切。如果有帮助的话,删除windows的system32。
唯一对我有效的方法是这里描述的(我运行的是ubuntu 14.04)。为了清晰起见,以下是我遵循的步骤:
sudo vim /etc/mysql/my.cnf Add the following lines at the end: [mysqld] skip-grant-tables sudo service mysql restart mysql -u root use mysql select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called password or authentication_string UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above FLUSH PRIVILEGES; exit sudo vim /etc/mysql/my.cnf Remove the lines added in step 2 if you want to keep your security standards. sudo service mysql restart
参考:https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
你可以尝试以下步骤来重置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密码
当你在你想要更改密码的系统上使用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密码在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;