我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?
我正在跟踪这个链接,但我在本地没有directadmin目录。
我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?
我正在跟踪这个链接,但我在本地没有directadmin目录。
当前回答
在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
其他回答
这里提供的答案似乎对我不起作用,事实证明,诀窍是: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
(完整的答案在这里:在MySQL 5.7用" plugin: auth_socket "修改用户密码)
你找不到它。它存储在一个数据库中,您需要根密码才能访问该数据库,即使您以某种方式获得了访问权限,它也会使用单向散列进行散列。您可以重置:如何重置Root用户密码
系统:
中佐的Linux 7 位于华盛顿市郊1414区
过程:
Open two shell sessions, logging in to one as the Linux root user and the other as a nonroot user with access to the mysql command. In your root session, stop the normal mysqld listener and start a listener which bypasses password authentication (note: this is a significant security risk as anyone with access to the mysql command may access your databases without a password. You may want to close active shell sessions and/or disable shell access before doing this): # systemctl stop mysqld # /usr/sbin/mysqld --skip-grant-tables -u mysql & In your nonroot session, log in to mysql and set the mysql root password: $ mysql mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass'); Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> quit; In your root session, kill the passwordless instance of mysqld and restore the normal mysqld listener to service: # kill %1 # systemctl start mysqld In your nonroot session, test the new root password you configured above: $ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ... mysql>
根据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 -uroot -p解决方案将不起作用,
在我的例子中,我使用了上面的一些答案来解决这个问题(Ubuntu 16)。结果是:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
如果你在屏幕上看到这段文字: mysqld_safe UNIX套接字文件目录“/var/run/mysqld”不存在。 然后做:
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables & # Look at the & at the end!
进入其他终端设置密码如下:
sudo mysql -u root
mysql> use mysql;
mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('__NEW__PASSWORD__');
mysql> flush privileges;
mysql> quit;
然后重新启动服务并登录
# end mysqld_safe in the other terminal
sudo service mysql start
sudo mysql -h 127.0.0.1 -uroot -p