如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
关于这个话题的大多数答案都过时了;在写这个答案之前,MySQL发生了两个主要的变化:
1-用户表中的“Password”字段已被“authentication_string”列取代。
2-“Password”加密功能:Password(“of some text”)已弃用。
更多信息请参考此链接:dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
其他回答
我遇到ubuntu 18.04和mysql 5.7的问题,这是解决方案
执行命令前请尝试重新启动mysql-server
sudo service mysql restart
Mysql-server >= 5.7
sudo mysql -uroot -p
USE mysql;
UPDATE user SET authentication_string=PASSWORD('YOUR_PASSWORD') WHERE User='root';
UPDATE user SET plugin="mysql_native_password";
FLUSH PRIVILEGES;
quit;
Mysql-server < 5.7
sudo mysql -uroot -p
USE mysql;
UPDATE user SET password=PASSWORD('YOUR_PASSWORD') WHERE User='root';
UPDATE user SET plugin="mysql_native_password";
FLUSH PRIVILEGES;
quit;
在我的例子中,这个选项很有用: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
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 8。*在Ubuntu上
停止MySQL服务,检查状态确认服务已停止
Sudo systemctl停止mysql Sudo systemctl status mysql
编辑systemd配置文件,这样您就可以在没有权限检查的情况下访问MySQL Sudo systemctl编辑mysql 复制并粘贴以下3行
(服务) ExecStart = ExecStart=/usr/sbin/mysqld——skip-grant-tables——skip-networking
粘贴行后按CTRL+0保存,然后按CTRL+X退出
重新加载mysql服务并启动它(使用——skip-grant-table启动服务)
Sudo systemctl daemon-reload Sudo systemctl启动mysql
5.现在无需密码即可连接MySQL服务器
sudo mysql -u root
6.通过运行加载授权表
mysql> FLUSH PRIVILEGES;
重置root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPasswordHere';
关闭mysql连接
mysql >退出
恢复对mysql systemd文件所做的修改
Sudo systemctl恢复mysql
重新加载mysql守护进程以进行更改。
Sudo systemctl daemon-reload
最后重新启动MySQL服务
Sudo systemctl restart mysql
现在用第7步设置的新密码连接mysql
你可以访问这个链接重置mysql 8的根密码了解更多细节。
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