如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
如何修改ubuntu服务器的MySQL root密码和用户名?我需要停止mysql服务之前,设置任何更改?
我有一个phpmyadmin设置以及,phpmyadmin会自动更新?
当前回答
这就像我为Ubuntu 16.04做的一样。 完全归功于下面的链接,因为我从那里得到了它。 [https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts] [1]
停止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 &
无需密码即可登录。
mysql -uroot mysql
更新root用户密码。 确保下面的查询至少更新了根帐户。 如果您愿意,进行一些选择并检查现有的值
UPDATE mysql.user SET
authentication_string=PASSWORD('YOURNEWPASSWORD'),
plugin='mysql_native_password' WHERE User='root';
EXIT;
关闭MySQL。
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
正常启动MySQL服务。
sudo service mysql start
其他回答
你可以尝试以下步骤来重置mysql的root密码:
首先停止Mysql服务
sudo /etc/init.d/mysql stop
以root用户登录,不需要密码 Sudo mysqld_safe—skip-grant-tables &
登录mysql终端后,你需要执行更多的命令:
use mysql;
UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';
flush privileges;
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
重启mysql服务器后 如果你仍然面临错误,你必须访问: 重置MySQL的root密码
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.
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 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文档中password()函数所说:
此函数在MySQL 8.0.11中被移除。
这将使mysql v8.0.11及更新版本的所有现有答案都失效。
根据mysql文档,重置root密码的新通用方法如下:
The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure): Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, if the server is started with the --skip-grant-tables option, it enables --skip-networking automatically to prevent remote connections. Connect to the MySQL server using the mysql client; no password is necessary because the server was started with --skip-grant-tables: shell> mysql In the mysql client, tell the server to reload the grant tables so that account-management statements work: mysql> FLUSH PRIVILEGES; Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use. To change the password for a root account with a different host name part, modify the instructions to use that host name. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables and --skip-networking options).