我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?

我正在跟踪这个链接,但我在本地没有directadmin目录。


当前回答

多亏了@thusharaK,我可以在不知道旧密码的情况下重置根密码。

在ubuntu上,我做了以下操作:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

然后在新的终端运行mysql:

mysql -u root

并执行如下命令修改密码:

UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;

在MySQL 5.7中,MySQL中的password字段。用户表字段被删除,现在字段名是'authentication_string'。

退出mysql安全模式,启动mysql服务:

mysqladmin shutdown
sudo service mysql start

其他回答

这里提供的答案似乎对我不起作用,事实证明,诀窍是: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password

(完整的答案在这里:在MySQL 5.7用" plugin: auth_socket "修改用户密码)

根据MySql版本的不同,该过程有所不同。按照您的版本所描述的步骤进行操作:

HINTS - Read before the instructions page for your version of MySql* In step 5: Instead of run CMD, create a shortcut on your desktop calling CDM.exe. Then right-click on the shortcut and select "Execute as Administrator". In step 6: Skip the first proposed version of the command and execute the second one, the one with the --defaults-file parameter Once you execute the command, if everything is ok, the CMD window remains open and the command of step 6 continues executing. Simply close the window (click 'x'), and then force close MySQl from the Task Manager. Delete the file with the SQL commands, and start again MySQL. The password must be changed now.

5.0 http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

5.1 http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

…只需在链接中更改版本(5.5,5.6,5.7)

mysql服务器安装后的默认密码是:mysql

多亏了@thusharaK,我可以在不知道旧密码的情况下重置根密码。

在ubuntu上,我做了以下操作:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

然后在新的终端运行mysql:

mysql -u root

并执行如下命令修改密码:

UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;

在MySQL 5.7中,MySQL中的password字段。用户表字段被删除,现在字段名是'authentication_string'。

退出mysql安全模式,启动mysql服务:

mysqladmin shutdown
sudo service mysql start

在Windows系统下,请按照以下步骤重置密码

从任务管理器中停止Mysql服务 创建一个文本文件并粘贴下面的语句

MySQL 5.7.5及以前版本: SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yournewpassword');


MySQL 5.7.6及以上版本: ALTER USER 'root'@'localhost'

保存为mysql-init.txt,并将其放在“C”盘。 打开命令提示符并粘贴以下内容

C:\\ > mysqld——init-file=C:\\mysql-init.txt