【札记】Linux下 MySQL-5.7.17 tar.gz 包方式安装部署后出现密码过期的问题解决(不修改/etc/my.cnf文件)

【问题描述】

在Oracle linux 6.8上安装完成MySQL-5.7.17(使用版本为:mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz)后:

[root@shh ~]# mysql --version
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

# service mysqld start

命令行启动正常,登录出现问题:

[root@shh ~]# mysql -uroot -p
Enter password: 
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.

根据提示:密码过期,必须使用一个mysql客户端登录修改密码后才能使用。

mysql的提示与日志提示都是比较模糊的,只能根据经验进行问题排查。


【解决方法】

使用以下方式解决:

1、关闭mysql服务

[root@shh ~]# service mysqld status
MySQL running (30500)[  OK  ]
[root@shh ~]# 
[root@shh ~]# 
[root@shh ~]# service mysqld stop
Shutting down MySQL..[  OK  ]
[root@shh ~]# 


2、进入mysql的工作目录 /usr/local/mysql/bin 使用mysql安全模式启动mysql,跳过mysql的登录权限验证

[root@shh ~]# cd /usr/local//mysql/bin/
[root@shh bin]# ./mysqld_safe --skip-grant-tables &
[1] 1557
[root@shh bin]# 2017-10-11T01:35:35.836730Z mysqld_safe Logging to '/usr/local/mysql/data/shhy-dw-application.err'.
2017-10-11T01:35:35.840516Z mysqld_safe Logging to '/usr/local/mysql/data/shhy-dw-application.err'.
2017-10-11T01:35:35.868903Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

执行完命令后,mysql会自动安全模式重启(注意:切记此时不要在再此shell窗口进行任何操作),此时,则新开ssh窗口或者使用远程机器(已安装MySQL客户端的Windows)的命令行进行连接访问:


3、命令行连接mysql数据库。此时无需指定密码。

[root@shh ~]# mysql -h10.10.9.35 -uroot 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select user,host,authentication_string,password_expired from mysql.user;
+-----------+-----------+-------------------------------------------+------------------+
| user      | host      | authentication_string                     | password_expired |
+-----------+-----------+-------------------------------------------+------------------+
| root      | localhost | *895A2D9FF0E9EFA56E84678045BB050034435B72 | Y                |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                |
+-----------+-----------+-------------------------------------------+------------------+
2 rows in set (0.00 sec)

mysql> update user set authentication_string=password('admin321') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> update user set password_expired='N' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update user set host='%' where user=root;
ERROR 1054 (42S22): Unknown column 'root' in 'where clause'
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,host,authentication_string,password_expired from mysql.user;
+-----------+-----------+-------------------------------------------+------------------+
| user      | host      | authentication_string                     | password_expired |
+-----------+-----------+-------------------------------------------+------------------+
| root      | %         | *2A29AD291780ABA691DA40E5900F63BCD40CB849 | N                |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                |
+-----------+-----------+-------------------------------------------+------------------+
2 rows in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


4、如需要可永久关闭mysql密码过期功能限制:

修改全局配置文件  /etc/my.cnf   或者 /usr/local/mysql/support-files/my-default.cnf 文件(最后同时加上)
如下(如有则直接修改):
[mysqld]
default_password_lifetime=0


5、关闭当前使用安全MySQL模式的服务,直接kill -9 解决


^C
[root@shh bin]# 
[root@shh bin]# 
[root@shh bin]# 
[root@shh bin]# ps -ef|grep mysql
root      1557  1437  0 09:35 pts/1    00:00:00 /bin/sh ./mysqld_safe --skip-grant-tables
mysql     1643  1557  0 09:35 pts/1    00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --log-error=/usr/local/mysql/data/shhy-dw-application.err --pid-file=/usr/local/mysql/data/shhy-dw-application.pid
root      1743  1719  0 09:51 pts/0    00:00:00 mysql -h10.10.9.35 -uroot
root      1953  1437  0 10:45 pts/1    00:00:00 grep mysql
[root@shh bin]# kill -9  1557
[root@shh bin]# kill -9  1643
[1]+  Killed                  ./mysqld_safe --skip-grant-tables
[root@shh bin]# ps -ef|grep mysql
root      1743  1719  0 09:51 pts/0    00:00:00 mysql -h10.10.9.35 -uroot
root      1956  1437  0 10:46 pts/1    00:00:00 grep mysql


重启服务,即可使用修改后的密码admin321进行访问了。


[root@shh bin]# service mysqld status
MySQL is not running, but PID file exists[FAILED]
[root@shh bin]# service mysqld start
Starting MySQL[  OK  ]
[root@shh bin]# ps -ef|grep mysql
root      1997     1  0 10:48 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/shhy-dw-application.pid
mysql     2099  1997  5 10:48 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/shhy-dw-application.err --pid-file=/usr/local/mysql/data/shhy-dw-application.pid
root      2131  1437  0 10:48 pts/1    00:00:00 grep mysql
[root@shh bin]# 


[root@shh bin]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)


Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
解压:将下载的zip解压到你想要放置的位置,我的是:E:\study\mysql-5.7.15-winx64 新建配置文件my.ini:在E:\study\mysql-5.7.15-winx64路径下有一个my-default.ini文件,该文件mysql默认的配置文件。我们可以复制一份,并改名为my.ini。打开该文件,在里面添加:skip-grant-tables( 用于跳过密码认证) 安装mysql: 以管理员权限打开cmd,然后进入E:\study\mysql-5.7.15-winx64\bin文件夹输入以下命令:mysqld --initialize (用于初始化mysqlMySQL会帮你自动进行初始化,例如生成data文件夹) 再输入:mysqld install(安装mysql)若安装成功,会提示Service successfully installed 安全模式打开:输入命令:mysqld --skip-grant-tables(跳过认证表),此时光标会跳到下一行一直闪烁。 新窗口启动服务:同样以管理员权限进入bin文件夹,输入命令:mysql -u root -p会提示输入密码,直接回车可以进入。此时就可以成功进入数据库了。 修改密码:输入use mysql;然后更改密码: update user set password=password("123456") where user="root";//旧版本 update user set authentication_string=password("123456") where user="root";//新版本 最后flush privileges;就可以了 重新使用密码登录:先在my.ini配置删除skip-grant-tables,然后在bin文件夹下输入net start mysql(若提示无法启动可能是刚刚的mysql还没有结束,可以打开任务管理器把mysqld.exe关闭),接着输入mysql -u root -p回车,然后输入你刚刚的密码,这里是:123456。可以看到成功登录进去。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值