输出: Stopping MySQL database server: mysqld. 第二步:启动mysql服务器,无密码:
mysqld_safe --skip-grant-tables &
输出:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
第三步:使用mysql客户端连接到mysql服务器:
mysql -u root
输出:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 56299
Server version: 5.6.34-1 (Debian)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
第四步:设置新的mysql root用户密码: MySQL5.7.5及更低版本
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
MySQL5.7.6及更新版本
mysql> use mysql;
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("newpass");
mysql> flush privileges;
mysql> quit
第五步:停止mysql服务器:
service mysql stop
输出:
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe --skip-grant-tables
2条答案
按热度按时间gjmwrych1#
看起来你根本没有设置密码。尝试登录,在密码字段中不键入任何内容。只需键入用户即可。
9bfwbjaz2#
从https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords
恢复mysql根密码
您可以通过以下五个简单步骤恢复mysql数据库服务器密码:
第1步:停止mysql服务器进程。
第2步:使用--skip grant tables选项启动mysql(mysqld)服务器/守护进程,这样它就不会提示输入密码。
第三步:以root用户身份连接到mysql服务器。
第四步:设置新的根密码。
第五步:退出并重启mysql服务器。
以下是您需要为每个步骤键入的命令(以root用户身份登录):
第1步:停止mysql服务:
输出:
Stopping MySQL database server: mysqld.
第二步:启动mysql服务器,无密码:输出:
第三步:使用mysql客户端连接到mysql服务器:
输出:
第四步:设置新的mysql root用户密码:
MySQL5.7.5及更低版本
MySQL5.7.6及更新版本
第五步:停止mysql服务器:
输出:
如果上面的命令无法停止mysql,也可以使用此命令停止mysql(哪个命令有效取决于mysql版本):
输出可能因linux发行版而异。别担心,除非它报告了一个错误。启动mysql服务器并进行测试: