1.前语
当你搭建了mysql服务,或许运用他人搭建好的MySQL服务,忘掉root暗码怎样办?今日跟我们简略共享下处理办法。
不要忘掉暗码,要记载好
因为MySQL不同版别处理的办法不一样,这儿为我们共享3个大版别的重置办法。
2.MySQL 5.1.26 重置root暗码(适用低版别的MySQL)
1.重启mysql服务,并在发动脚本里增加参数–skip-grant-tables 。
$ mysql -h127.0.0.1 -P3306 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.26-rc Source distribution
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> use mysql
//将暗码置空
mysql> update user set password=password('你要设置的暗码') where user='root';
mysql> flush privileges;
2.用root用户进行空暗码登录设置新暗码。
$ ./mysqld_safe --defaults-file=./my.cnf &
3.去除免暗码登录,并重启mysql服务注释掉过程1的句子 。
$ ./mysqld_safe --defaults-file=./my.cnf &
4.这时候运用新暗码登录。
3.MySQL 5.7.28 重置root暗码
1.修正配置文件my.cnf免暗码登录。
在【mysqld】模块增加:skip-grant-tables 保存退出;
2.重启mysql服务。
3.用root用户进行登录设置新暗码,留意从5.7版别开端,不再是password这个字段赋值。
mysql> use mysql
//将暗码置空
mysql> update user set authentication_string=password('你要设置的暗码') where user='root';
mysql> flush privileges;
新的语法
4.去除免暗码登录,并重启mysql服务注释掉过程1的句子 。
# skip-grant-tables
5.这时候运用新暗码登录。
4.MySQL 8.0忘掉暗码后重置暗码
1.修正配置文件my.cnf免暗码登录。
在【mysqld】模块增加:skip-grant-tables 保存退出;
2.重启mysql服务。
3.用root用户进行登录置空暗码,这一步很重要。
mysql> use mysql
//将暗码置空
mysql> update user set authentication_string = '' where user = 'root';
4.去除免暗码登录,并重启mysql服务注释掉过程1的句子。
# skip-grant-tables
5.用root用户进行空暗码登录修正暗码。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root暗码';
留意:root暗码需求复杂点
5.MySQL 5.7.28 创立用户并设置暗码
上面讲了root怎样重置,下面趁便跟我们讲下怎样创立用户暗码。
$ 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)
5.完毕
经过三个不同版别的MySQL版别,你知道怎样重置数据库root暗码了吗?
是不是很简略,你也能够做到的。
