修改mysql密码:
一丶知道旧密码的情况
[root@mysql50 ~]# mysqladmin -u root -p password "abc123...Q"
Enter password: //输入旧密码
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
前提是操作系统的root用户
二丶不知道密码的情况下:
1.进入/etc/mycnf下添加skip-grant-tables
2.重启服务
3.进入mysql 修改密码
4.刷新
5.再次进入/etc/mycnf下删除skip-grant-tables
6.重启服务
7.登录mysql就可以看出,密码以成功修改
[root@mysql50 ~]# vim /etc/my.cnf
skip-grant-tables //不验证登录
:wq //保存退出
[root@mysql50 ~]# systemctl restart mysqld //修改完配置文件后,重启服务
[root@mysql50 ~]# mysql
mysql> //直接进入mysql
mysql> update mysql.user set authentication_string=password("abc123...A")
-> where
-> user="root" and host="localhost";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1 //修改密码
mysql> flush privileges; //刷新
Query OK, 0 rows affected (0.00 sec)
mysql> exit //退出
Bye
[root@mysql50 ~]# vim /etc/my.cnf //删除那段话
[root@mysql50 ~]# systemctl restart mysqld //重启
//尝试无密码进入数据库
[root@mysql50 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@mysql50 ~]# mysql -u root -p"abc123...A"
mysql>
三丶第一次进入mysql数据库
1.创建mysql时 自动生成默认密码 在/var/log/mysqld.log
2.进入数据库
3.修改密码策略
4.修改密码长度
5.修改密码
[root@localhost ~]# grep password /var/log/mysqld.log
2019-08-30T11:15:14.406870Z 1 [Note] A temporary password is generated for root@localhost: RbPf&g_H9_vf
[root@localhost ~]# mysql -u root -p" RbPf&g_H9_vf"
mysql>
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.01 sec)
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user user() identified by "123456"
-> ;
Query OK, 0 rows affected (0.00 sec)
永久修改密码策略
在配置文件/etc/my.cnf
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
validate_password_policy=0
validate_password_length=6