mysql数据库修改密码命令(mysql修改密码的3种方式)

1.前言

当你搭建了MySQL服务,或者使用别人搭建好的MySQL服务,忘记root密码怎么办?今天跟大家简单分享下处理方法。小白告诉你MySQL密码重置方法

不要忘记密码,要记录好

由于MySQL不同版本处理的方式不一样,这里为大家分享3个大版本的重置方法。

2.MySQL 5.1.26 重置root密码(适用低版本的MySQL)

1.重启mysql服务,并在启动脚本里添加参数–skip-grant-tables 。

$ mysql -h127.0.0.1 -P3306 -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or g.Your MySQL connection id is 1Server version: 5.1.26-rc Source distributionType '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 &

mysql数据库修改密码命令(mysql修改密码的3种方式)

新的语法

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';

mysql数据库修改密码命令(mysql修改密码的3种方式)

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 -pmysql> grant all privileges on testuser.* to testuser@'%' identified by 'testuser';ERROR 1290 (HY000): Unknown error 1290mysql> 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密码了吗?

是不是很简单,你也可以做到的。

(0)
小多多的头像小多多创始人

相关推荐

发表回复

登录后才能评论