如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
停止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 &
5.无需密码登录。 Mysql -uroot Mysql
6.更新root用户密码。
更新mysql。user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE user ='root' AND Host='%'; 退出;
关闭MySQL。 sudo mysqladmin -S /var/run/mysqld/mysqld.袜子关闭 正常启动MySQL服务。 Sudo服务mysql启动
其他回答
这就是我的解决方案。我在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';
如果你知道你当前的密码,你不需要停止mysql服务器。 打开ubuntu终端。 登录mysql使用:
mysql - username -p
然后输入密码。 这将带您进入mysql控制台。 在控制台内部,输入:
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
然后使用:
> flush privileges;
然后你就完成了。
正如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).
对我有用的(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
在我的例子中,这个选项很有用:https://stackoverflow.com/a/49610152/13760371 谢谢你,拉胡尔。
除了下面的时刻,当我尝试输入命令:
UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
控制台发出警告:
1681 'password' is deprecated and will be removed in a future release
用这个命令治愈:
UPDATE mysql.user SET authentication_string=CONCAT('*', UPPER(SHA1(UNHEX(SHA1('NEWPASSWORD'))))), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
MySQL版本5.7.X
我的版本:
1. > sudo service mysql stop
2. > sudo mkdir /var/run/mysqld
3. > sudo chown mysql: /var/run/mysqld
4. > sudo mysqld_safe --skip-grant-tables --skip-networking &
5. > mysql -uroot mysql
6. > UPDATE mysql.user SET authentication_string=CONCAT('*', UPPER(SHA1(UNHEX(SHA1('NEWPASSWORD'))))), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
7. > \q;
8. > sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
9. > sudo service mysql start