如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
I had to go this route on Ubuntu 16.04.1 LTS. It is somewhat of a mix of some of the other answers above - but none of them helped. I spent an hour or more trying all other suggestions from MySql website to everything on SO, I finally got it working with: Note: while it showed Enter password for user root, I didnt have the original password so I just entered the same password to be used as the new password. Note: there was no /var/log/mysqld.log only /var/log/mysql/error.log Also note this did not work for me: sudo dpkg-reconfigure mysql-server-5.7 Nor did: sudo dpkg-reconfigure --force mysql-server-5.5 Make MySQL service directory. sudo mkdir /var/run/mysqld Give MySQL user permission to write to the service directory. sudo chown mysql: /var/run/mysqld Then:
kill the current mysqld pid run mysqld with sudo /usr/sbin/mysqld & run /usr/bin/mysql_secure_installation Output from mysql_secure_installation root@myServer:~# /usr/bin/mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: no Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: Re-enter new password: By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y Dropping test database... Success. Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
其他回答
该任务指导用户在Ubuntu操作系统下设置/修改/重置MySQL root密码。在终端中输入以下行。
停止MySQL服务器:sudo /etc/init.d / mysql停止 (在某些情况下,如果/var/run/mysqld不存在,你必须首先创建它:sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld 启动mysqld配置:sudo mysqld——skip-grant-tables & 以root身份登录MySQL: MySQL -u root MySQL 用你的新密码替换YOURNEWPASSWORD:
MySQL < 8.0
UPDATE mysql.user SET Password = PASSWORD('YOURNEWPASSWORD') WHERE User = 'root';
FLUSH PRIVILEGES;
如果你的MySQL使用新的认证插件,你将需要使用:update user set plugin="mysql_native_password" where user ='root';在冲洗特权之前。
注意:在某些版本,如果密码列不存在,你可能想尝试: UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';
注意:这种方法不是最安全的重置密码的方法,但它是有效的。
对于MySQL >= 8.0
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';
FLUSH PRIVILEGES;
最后一步:
正如@lambart的评论中所提到的,你可能需要杀死你启动的临时无密码mysql进程,即sudo killall -9 mysqld,然后启动正常的守护进程:sudo service mysql start
引用:
该任务指导用户在Ubuntu Linux下设置/修改/重置MySQL root密码 如何重置Root用户密码(v5.6) 如何重置Root用户密码(v8.0)
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 root密码。
此方法将密码暴露到命令行历史记录中,这些命令应该以root身份运行。
通过mysql命令行工具登录: Mysql -uroot -poldpassword 执行如下命令: SET PASSWORD FOR root@ localhost = PASSWORD('newpassword');
or
运行此命令,为当前用户设置密码(在本例中为'root'): SET PASSWORD = PASSWORD('newpassword');
首先执行以下命令:
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。
要更新“root”Mysql用户密码,你必须记住,你将需要超级用户权限。如果您拥有超级用户权限,请尝试执行以下命令:
MySQL 5.7.6及以上版本
sudo su
service mysql stop
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
\q;
exit
mysql -u root -p MyNewPass
MySQL 5.7.5及更早版本
sudo su
service mysql stop
mysql -u root
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
\q;
exit
mysql -u root -p MyNewPass