最近在mac本上装了mysql也没怎么用,今天打算来测试一个项目需要导入一些数据,绞尽脑汁也想不出来密码了。只好来破解密码了。
其实重点就这一条语句我也不知道怎么能扯这么多内容
以安全模式登录后执行如下语句即可,然后重新启动mysql服务 登录即可无需密码。
update mysql.user set authentication_string='' where user='root';
如果您的问题已经解决了下面的内退就是废话,就不用往下看了,时间宝贵。
处理说明
先说说处理方法,mysql8版本的密码重置和之前的版本有所不同。
处理方法为如下步骤
-
1、关闭mysql服务
-
2、以安全模式启动mysql服务 加上参数–skip-grant-tables --user=mysql
-
3、完成第二步骤后即可不用密码登录,登录后先将用户的
authentication_string
字段置空。 -
4、然后再以正常模式启动mysql服务
-
5、让后以没有密码的方式登录,然后再按照修改密码的方式改成你想要修改的密码。。
处理过程
#### 0、以下为密码错误提示
mac@MacdeMacBook-Pro ~ % mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mac@MacdeMacBook-Pro ~ % mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
#### 1、关闭mysql服务
mac@MacdeMacBook-Pro bin % killall mysqld
#### 2、以安全模式启动mysql服务
mac@MacdeMacBook-Pro bin % mysqld_safe --skip-grant-tables --user=mysql &
[1] 1870
mac@MacdeMacBook-Pro bin % 2020-11-21T14:25:00.6NZ mysqld_safe Logging to '/usr/local/var/mysql/MacdeMBP.err'.
2020-11-21T14:25:00.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
#### 3、登录mysql
mac@MacdeMacBook-Pro bin % mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.21 Homebrew
Copyright (c) 2000, 2020, 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.
#### 以下这些命令在mysql8之前都可以使用的目前也不行了
mysql> set password=password("111111");
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'password("111111")' at line 1
mysql> update mysql.user set authentication_string=password("111111") where user="root";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("111111") where user="root"' at line 1
#### 4、重点在此直接将密码置空即可。。。
mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> exit
Bye
mac@MacdeMacBook-Pro bin % killall mysqld
mac@MacdeMacBook-Pro bin % 2020-11-21T14:47:27.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/MacdeMBP.pid ended
[1] + done mysqld_safe --skip-grant-tables --user=mysql
mac@MacdeMacBook-Pro bin % mysqld start
mac@MacdeMacBook-Pro bin % mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Homebrew
Copyright (c) 2000, 2020, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> alter user 'root'@'localhost' identified by 'Cmm111111%%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)