alter user 'root'@'localhost' identified by "123456"; # alter user 'root'@'localhost' identified WITH caching_sha2_password by "123456"; #创建远程连接 create user root@'%' identified by '123456'; grant all privileges on *.* to root@'%'; flush privileges;
无密码的方式,可用于找回密码。
输入一百次也输入不对默认密码 配置文件 MySQL 免密码登录 编辑 MySQL 的配置文件
1 2 3
vim /etc/my.cnf #在 datadir开头的下面一行加入下面这句 skip-grant-tables
修改密码(记得删除my.cnf文件的东西)
1 2 3
bin/mysql use mysql; update user SET Password = 'new-password' WHERE User = 'root';
2021-04-12T05:57:03.198202Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2021-04-12T05:57:03.198234Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.23) initializing of server in progress as process 6289 2021-04-12T05:57:03.199359Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2021-04-12T05:57:03.199363Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it. 2021-04-12T05:57:03.199405Z 0 [ERROR] [MY-010119] [Server] Aborting 2021-04-12T05:57:03.199471Z 0 [System] [MY-010910] [Server] /usr/bin/mysqld: Shutdown complete (mysqld 8.0.23) Source distribution.