alter user 'root'@'localhost' identified by 'password'; mysql -u root -p #登录后 mysql> alter user 'root'@'localhost' identified by 'root'; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
C:\Windows\system32>mysql -u root -P 3307 -p Enter password: **** #root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 17 Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
SET PASSWORD FOR 'user'@'host' = PASSWORD('newpassword'); 用户 ip SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword'); C:\Users\14763>mysql -uroot -p Enter password: **** #登录后
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root123'); Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit; Bye
C:\Users\14763>mysql -uroot -p Enter password: ****** #root123 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 Server version: 5.7.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
C:\>"C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin\mysql.exe"
#结果 ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
C:\>"C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin\mysqld.exe"
#结果 mysqld: Can't change dir to 'C:\Program Files (x86)\MySQL\MySQL Server 5.7\data\' (Errcode: 2 - No such file or directory) 2023-05-06T06:19:24.084707Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2023-05-06T06:19:24.084790Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled 2023-05-06T06:19:24.085328Z 0 [Note] C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin\mysqld.exe (mysqld 5.7.36) starting as process 7424 ... 2023-05-06T06:19:24.089909Z 0 [Warning] Can't create test file C:\Program Files (x86)\MySQL\MySQL Server 5.7\data\DESKTOP-ECFIPC8.lower-test 2023-05-06T06:19:24.090171Z 0 [Warning] Can't create test file C:\Program Files (x86)\MySQL\MySQL Server 5.7\data\DESKTOP-ECFIPC8.lower-test 2023-05-06T06:19:24.091955Z 0 [ERROR] failed to set datadir to C:\Program Files (x86)\MySQL\MySQL Server 5.7\data\ 2023-05-06T06:19:24.092541Z 0 [ERROR] Aborting
2023-05-06T06:19:24.093154Z 0 [Note] Binlog end 2023-05-06T06:19:24.094298Z 0 [Note] C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin\mysqld.exe: Shutdown complete
C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin>mysql -u root -p Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.7.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
use mysql; update user set authentication_string=''where user='root'; flush privileges;#刷新权限
5.设置加密规则并更新新密码,授权(直接复制这些SQL语句你的密码会更新为123456
1 2 3 4
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; alter user 'root'@'localhost' identified by '123456'; grant all privileges on *.* to "root"@'localhost'; flush privileges;#刷新权限
C:\Windows\system32>mysql -uroot -P 3307 -p Enter password: #回车进入即可 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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'forhelp. Type '\c' to clear the current input statement.
mysql> use mysql; Database changed mysql> update user set authentication_string=''where user='root'; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0
mysql> exit; #此处可能会卡住 #mysql> eixt; #^C -- Sorry, cannot connect to the server to kill query, giving up ... #不理会,关闭窗口就行,重新开一个cmd Bye
C:\Windows\system32>mysql -uroot -P 3307 -p Enter password: ****** #123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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'forhelp. Type '\c' to clear the current input statement.
mysql>
MySQL5.7
暂停服务(以管理员运行cmd)
1
net stop mysql57
修改my.ini配置文件,在[mysqld]下面加上这样的一句话
1
skip-grant-tables
重启服务(以管理员运行cmd)
1
net start mysql57
登录mysql
1
mysql -uroot -p
置空密码
1 2 3
use mysql; update user set authentication_string=''where user='root'; flush privileges;#刷新权限