07.关于MySQL管理员密码设置

7.1 为管理员 root 用户设置密码并修改方法之一

mysqladmin –uroot password ‘pcwangjixuan’ <--没有密码的用户设置密码命令
mysqladmin –uroot –p123456 password ‘pcwangjixuan’ –S /data/3306/mysql.sock <--适合多实例修改密码​

7.2 修改管理员 root 密码法二(sql 语句修改)

mysql> UPDATE mysql.user SET password=PASSWORD('123456') WHERE user='root' and host='localhost'

 7.3 找回丢失的 mysql root 用户密码(单实例和多实例)

单实例:

1、首先停止 mysql
[root@db01 ~]# /etc/init.d/mysqld stop
2、使用—skip-grant-tables 启动 mysql,忽略授权登录验证
mysqld_safe –skip-grant-tables –user=mysql &
mysql <--登录时空密码
提示:在启动时加—skip-grant-tables 参数,表示忽略授权表验证
3、登录 mysql,设置 root 用户密码
mysql> update mysql.user SET password=PASSWORD('pcwangjixuan') WHERE user='root' and
host='lcoalhost';
4、停止 mysql 服务,重新启动 mysql
[root@db01 ~]# /etc/init.d/mysqld restart​

多实例

1、 首先停止 mysql
[root@mysql ~]# /mysqldata/3306/mysql stop
Stoping MySQL...
2、使用—skip-grant-tables 启动 mysql,忽略授权登录验证
[root@mysql ~]# /application/mysql/bin/mysqld_safe --defaults-file=/mysqldata/3306/my.cnf --
skip-grant-tables &
3、登录 mysql,设置 root 用户密码
[root@mysql ~]# mysql -u root -S /mysqldata/3306/mysql.sock
mysql> update mysql.user SET password=PASSWORD('pcwangjixuan1') WHERE user='root' and
host='localhost';
Query OK, 1 row affected (0.10 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
4、停止服务,重新启动
[root@mysql ~]# /mysqldata/3306/mysql stop
[root@mysql ~]# /mysqldata/3306/mysql start

 

posted @ 2020-03-21 15:06  流氓徐志摩  阅读(592)  评论(0编辑  收藏  举报