MySQL相关操作
2020-05-19 本文已影响0人
testerzhang
前言
日常会需要使用MySQL,这里备忘下,后续持续更新。
MySQL 5.7.28 创建用户并设置密码
$ mysql -h127.0.0.1 -P3306 -uroot -p
mysql> grant all privileges on testuser.* to testuser@'%' identified by 'testuser';
ERROR 1290 (HY000): Unknown error 1290
mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)
mysql> grant all privileges on testuser.* to testuser@'%' identified by 'testuser';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MySQL 8.0忘记密码后重置密码
- 修改配置文件
my.cnf
免密码登录
在【mysqld】模块添加:skip-grant-tables
保存退出;
-
重启mysql服务
-
用root用户进行登录置空密码
mysql> use mysql
//将密码置空
mysql> update user set authentication_string = '' where user = 'root';
-
去除免密码登录,并重启mysql服务
注释掉步骤1的语句# skip-grant-tables
-
用root用户进行空密码登录修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root密码';
注意:root密码需要复杂点