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

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


当前回答

使用Debian / Ubuntu mysql包,可以使用Debian -sys- maintenance用户登录,该用户拥有所有的权限,密码保存在/etc/mysql/ Debian .cnf文件中

其他回答

如果您在过去已经设置了密码,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

有一件事绊倒了我在一个新的MySQL安装,并想知道为什么我不能得到默认密码工作,为什么甚至重置方法不起作用。 在Ubuntu 18上,MySQL服务器的最新版本在默认情况下根本不使用root用户的密码认证。这意味着不管你设置它为什么,它都不会让你使用它。它期望您从特权套接字登录。

mysql -u root -p

即使您使用了正确的密码,这也不起作用。

相反,你需要使用:

sudo mysql

这将适用于任何密码。 然后输入

 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password you want to use';

然后登出,现在它将接受您的密码。

根据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)

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

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

去phpMyAdmin > config.inc.php > $cfg['Servers'][$i]['password'] = ";