如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
唯一对我有效的方法是这里描述的(我运行的是ubuntu 14.04)。为了清晰起见,以下是我遵循的步骤:
sudo vim /etc/mysql/my.cnf Add the following lines at the end: [mysqld] skip-grant-tables sudo service mysql restart mysql -u root use mysql select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called password or authentication_string UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above FLUSH PRIVILEGES; exit sudo vim /etc/mysql/my.cnf Remove the lines added in step 2 if you want to keep your security standards. sudo service mysql restart
参考:https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
其他回答
回应rogerdpack的评论:如果你不知道MySQL的根密码,并且你不关心MySQL的数据/设置,你可以重新安装它并重置根密码,如下所示:
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo rm -rf /var/lib/mysql
sudo apt-get install -y mysql-server mysql-client
安装过程中,您可以选择root用户的密码:
我还没有看到MySQL 8.0指南中推荐的官方步骤,这是唯一适合我的步骤。下面是这些步骤的总结。
Stop the MySQL server if it is running. Look in /var/lib/mysql/, /var/run/mysqld/, or /usr/local/mysql/data/ to find the pid file with the server's process ID. Generally the file begins with either mysqld or your system's host name and ends with .pid. Replace mysql-data-directory and host_name that you just found, in the following command: $ sudo kill `sudo cat /mysql-data-directory/host_name.pid` This command will create a text file in /tmp/mysql-init with the SQL statement and makes the mysql user the owner. Replace in the command MyNewPass with your own password. $ echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';" > /tmp/mysql-init && sudo chown mysql /tmp/mysql-init Start the MySQL server by running the following command on the command line. After this the password is updated and you can close the server again with CTRL+C. $ sudo mysqld --user=mysql --init-file=/tmp/mysql-init & Remove the temporary file with your password: $ sudo rm /tmp/mysql-init
停止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启动
如果你想修改MySQL root密码,在终端输入:
Sudo dpkg-reconfigure mysql-server-5.5
MySQL守护进程将被停止,并提示您输入新密码。
对于mysql 5.6,这个命令有效,你可以通过向导设置密码:
sudo dpkg-reconfigure mysql-server-5.6