今天接到主从复制失败告警,查看MySQL,发现MySQL能够登陆但是执行命令报错,

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

因为是用户密码过期了

解决办法:

登陆MySQL命令行,执行

set password=password("password");

flush privileges;

#设置用户密码永不过期
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
查看用户密码默认过期时间设置,默认360天
mysql> show global variables like "default_password_lifetime";
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| default_password_lifetime | |
+---------------------------+-------+
row in set (0.00 sec) 设置用户密码永不过期(临时生效)
mysql> SET GLOBAL default_password_lifetime = ;
Query OK, rows affected (0.00 sec) mysql> show global variables like "default_password_lifetime";
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| default_password_lifetime | |
+---------------------------+-------+
row in set (0.00 sec)
如果要设置密码永不过期,设置my.cnf
vi /etc/my.cnf
添加
#设置用户密码永不过期
default_password_lifetime=0 这样重启后也是没问题的
查看用户密码设置
mysql> select user,host,password_expired,password_last_changed,password_lifetime from mysql.user;
+----------------+-----------+------------------+-----------------------+-------------------+
| user | host | password_expired | password_last_changed | password_lifetime |
+----------------+-----------+------------------+-----------------------+-------------------+
| root | localhost | N | -- :: | |
| mysql.sys | localhost | N | -- :: | NULL |
| root | % | N | -- :: | NULL |
| zabbix_monitor | localhost | N | -- :: | NULL |
+----------------+-----------+------------------+-----------------------+-------------------+
rows in set (0.00 sec)
创建一个有效期30天的用户
create user tt@'%' identified by '' password expire interval day; mysql> select user,host,password_expired,password_last_changed,password_lifetime from mysql.user;
+-----------+------------+------------------+-----------------------+-------------------+
| user | host | password_expired | password_last_changed | password_lifetime |
+-----------+------------+------------------+-----------------------+-------------------+
| root | localhost | N | -- :: | NULL |
| mysql.sys | localhost | N | -- :: | NULL |
| mysync | 10.73..% | N | -- :: | NULL |
| tt | % | N | -- :: | |
+-----------+------------+------------------+-----------------------+-------------------+

参考

mysql-5.7 密码过期详解 http://www.mamicode.com/info-detail-2042849.html

Mysql 5.7 账户过期设置 - CSDN博客 http://blog.csdn.net/jc_benben/article/details/77934469

MySQL用户密码过期登陆报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.的更多相关文章

  1. 第一次登录mysql,使用任何命令都报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    问题: 使用临时密码登录成功后,使用任何myql命令,例如show databases;都提示下面的报错 ERROR 1820 (HY000): You must reset your passwor ...

  2. MySQL5.7 报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement

    MySQL5.7 报错 : ERROR 1820 (HY000): You must reset your password using ALTER USER statement before exe ...

  3. mysql5.7初始化密码报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before

    mysql初始化密码常见报错问题1,mysql5.6是密码为空直接进入数据库的,但是mysql5.7就需要初始密码 cat /var/log/mysqld.log | grep password1 2 ...

  4. mysql5.7初始化密码报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement

    mysql初始化密码常见报错问题 1,mysql5.6是密码为空直接进入数据库的,但是mysql5.7就需要初始密码 cat /var/log/mysqld.log | grep password 2 ...

  5. mysql 报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin

    解决办法1. 修改用户密码mysql> alter user 'root'@'localhost' identified by 'youpassword'; 或者 mysql> set p ...

  6. MySQL数据库使用报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    今天MySQL数据库,在使用的过程中一直报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement be ...

  7. MySQL root账户密码设为“root”后执行命令提示ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    修改root账户密码为“root”后,提示ERROR 1820 (HY000): You must reset your password using ALTER USER statement bef ...

  8. MySQL:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    解决方法: 修改密码:alter user 'root'@'localhost' identified by '123456'; mysql> use mysql; ERROR 1820 (HY ...

  9. 【MySQL】ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing

    今天上午遇到了一个问题,新创建的mysql5.7的数据库,由于初始化有点问题,没有给root密码,用了免密码登录. 但是,修改了root密码之后,把配置中的免密登录的配置注释掉后,重启服务.服务正常启 ...

随机推荐

  1. OpenState之 Mac学习 实验

    OpenState之 Mac学习 实验 目录 OpenState安装 Port Knocking 实验 Mac Learning 实验 环境要求: 系统ubuntu 14.04 mininet:2.3 ...

  2. python获取命令行参数的方法(汇总)

    介绍python获取命令行参数的方法:getopt模和argparse模块. python版本:2.7 一.getopt模块 主要用到了模块中的函数: options, args = getopt.g ...

  3. CI框架 default_controller 如何设置为:'目录/Controller' 转

    闲谈 前几天,我的室友发现了一个问题:CI框架的Router.php文件的default_controller设置为application\controllers文件下的 一级PHP文件名 就可以,设 ...

  4. linux分区命名

    linux中任何内容都是文件 硬盘 文件 用户 都是文件 硬件设备文件名称 ide硬盘 /dev/hd[a-d] scsi/sata/usb硬盘 /dev/sd[a-p] 光驱 /dev/cdrom/ ...

  5. Study From DevOps 学习交流会议

    1.今天下午参加了 软件集团的 爱城市的devops的沟通会议,了解到他们是通过bash的方式来执行jenkins的build以及创建 jenkins的 project 等内容.晚上回来简单实验了下. ...

  6. [转载] 什么是istio 官网内容

    网址:https://preliminary.istio.io/zh/docs/concepts/what-is-istio/ mark 一下 1.0 昨天刚发布. 2018.7.31 Istio 是 ...

  7. c语言和c++有什么区别

    差不多是win98跟winXP的关系.C++是在C的基础上增加了新的理论,玩出了新的花样.所以叫C加加. C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输 ...

  8. Hibernate性能优化之EHCache缓存

    像Hibernate这种ORM框架,相较于JDBC操作,需要有更复杂的机制来实现映射.对象状态管理等,因此在性能和效率上有一定的损耗. 在保证避免映射产生低效的SQL操作外,缓存是提升Hibernat ...

  9. MySql_创建用户并赋予权限

    MySql两种创建用户方式 win+r cmd C:\Users\Administrator>mysql -uroot -proot # 方式一 mysql> insert into my ...

  10. C/C++ Bug记录

    链接错误解决方法 1. 检查库是否链接正确 2. 库的顺序是否合理(如果库之间有依赖关系的话) 3. 检查obj文件是否存在既有C编译的,也有C++编译的,如果存在,用extern "C&q ...