如何修改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.
其他回答
设置MySQL密码
停止MySQL数据库服务
sudo /etc/init.d/mysql stop
创建一个新的mysqld目录
Sudo mkdir /var/run/mysqld/
给予mysql用户访问权限
Sudo chown mysql /var/run/mysqld/
以安全模式启动MySQL…
Sudo mysqld_safe—skip-grant-tables &
无需密码登录数据库服务器
Sudo mysql -u root
使用默认的mysql数据库
使用mysql;
修改root密码
update user set authentication_string=PASSWORD(" new_passwor_here ") where user ='root';
保存更改 冲洗特权; 退出; 停止MySQL安全模式,启动MySQL默认服务
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
使用root新密码重新登录MySQL数据库
-u root -p
***来源:https://websiteforstudents.com/resetting-mysql-root-password-on-ubuntu-16-04-17-10-and-18-04-lts/
1.打开nano / vim,创建一个包含以下内容的文件,并将文件保存为~/mysql-pwd
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEWPASSWORD';
停止mysql sudo systemctl停止mysql 执行sudo mysqld -init-file=~/mysql-pwd命令 重启mysql sudo systemctl start mysql 现在登录mysql -u root -p。password将是你的NEWPASSWORD
你不需要这些。只需登录:
Mysql -u root -p
然后按照mysql>提示修改当前用户的密码:
mysql> set password=password('the_new_password');
mysql> flush privileges;
对于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
现在享受
首先执行以下命令:
sudo mysql
然后你应该检查你的MySQL用户帐户使用的身份验证方法。运行这个命令
SELECT user,authentication_string,plugin,host FROM mysql.user;
现在你可以看到这样的东西:
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | | auth_socket | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
在上面的表格中,你可以看到你所有的mysql用户的帐户状态&如果你已经设置了root帐户的密码,然后在插件列中看到mysql_native_password而不是auth_socket。 总之,要更改root密码,您应该运行以下命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
请务必将密码更改为您选择的强密码。 然后重新加载你的服务器,把你的新变化生效运行这个;
FLUSH PRIVILEGES;
所以再次检查你的mysql所使用的认证方法,通过下面的命令:
SELECT user,authentication_string,plugin,host FROM mysql.user;
现在输出是:
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | *3636DACC8616D997782ADD0839F92C1571D6D78F | mysql_native_password | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
正如您在授权表中看到的,您的根帐户具有mysql_native_password . 现在你可以退出MYSQL shell了
exit;
就是这样。只是你应该通过sudo service mysql restart重新启动mysql。 现在你可以用root帐号和密码轻松登录mysql。