如何修改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!
其他回答
关于这个话题的大多数答案都过时了;在写这个答案之前,MySQL发生了两个主要的变化:
1-用户表中的“Password”字段已被“authentication_string”列取代。
2-“Password”加密功能:Password(“of some text”)已弃用。
更多信息请参考此链接:dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
官方和简单的方法来重置根密码在ubuntu服务器…
如果你在16.04 14.04 12.04
sudo dpkg-reconfigure mysql-server-5.5
如果你在10.04:
sudo dpkg-reconfigure mysql-server-5.1
如果您不确定安装了哪个mysql-server版本,您可以尝试:
dpkg --get-selections | grep mysql-server
mysql-server-5.7的更新说明
请注意,如果您使用的是mysql-server-5.7,则不能使用上面所示的更简单的dpkg-reconfigure方法。
如果你知道密码,登录并运行这个:
UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE USER='root';
FLUSH PRIVILEGES;
或者,您可以使用以下方法:
sudo mysql_secure_installation
这将询问您一系列关于保护安装的问题(强烈推荐),包括是否需要提供新的根密码。
如果你不知道root密码,请参考这个以ubuntu为中心的进程写上去。
查看更多信息:
https://help.ubuntu.com/16.04/serverguide/mysql.html https://help.ubuntu.com/14.04/serverguide/mysql.html
重置或修改密码请输入sudo dpkg-reconfigure mysql-server-X。X (X.X是mysql版本你已经安装,即5.6,5.7),然后你会提示一个屏幕,你必须设置新密码,然后在下一步确认密码,只是等待一会儿。就是这样。
对于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
现在享受
下面的步骤对我很有效。我使用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的根密码了解更多细节。