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

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


当前回答

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

其他回答

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

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

多亏了@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

系统:

中佐的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根密码,好吧,我已经在mysql 5.5上尝试过了,所以不知道其他新版本是否工作良好

nano ~/.my.cnf

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