centos下安装mysql5.7后,强行修改mysql的root密码

来源:互联网 发布:淘宝默认几天自动付款 编辑:程序博客网 时间:2024/04/29 01:36

昨天在centos下安装mysql5.7后,却发现无法登陆,才新安装的mysql,初始密码应该没有,但是无论如何都无法登陆(提示密码错误),没办法,只好强行修改mysql密码。


输入

[root@localhost bin]# mysqld_safe --skip-grant-tables &

这句话相当于进入mysql的安全模式。


输入上面这条命令可能会出现错误如下:

[3] 7135[2]   Exit 127                mysqld_stae --skip-grant-tables[root@localhost bin]# Usage: grep [OPTION]... PATTERN [FILE]...Try `grep --help' for more information.grep: write error: Broken pipe2016-04-02T10:16:02.306271Z mysqld_safe Logging to '/opt/mysql/data/localhost.localdomain.err'.2016-04-02T10:16:02.315564Z mysqld_safe The file /usr/local/mysql/bin/mysqlddoes not exist or is not executable. Please cd to the mysql installationdirectory and restart this script from there as follows:./bin/mysqld_safe&See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information[3]+  Exit 1                  mysqld_safe --skip-grant-tables

根据错误提示在/usr/local下创建文件夹mysql/bin/mysqld


创建好文件夹后,准备开启mysql,但是在这之前先检查一下mysql是否开启

[root@localhost ~]# ps -ef|grep mysqld

如果开启使用kill -15 [pid]杀死mysql。如下:

[root@localhost ~]# ps -ef|grep mysqldroot      6946     1  0 18:15 ?        00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe --datadir=/opt/mysql/data --pid-file=/opt/mysql/data/localhost.localdomain.pidmysql     7104  6946  0 18:15 ?        00:00:00 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/data/localhost.localdomain.err --pid-file=/opt/mysql/data/localhost.localdomain.pid --port=3306root      7558  7542  0 18:22 pts/0    00:00:00 grep mysqld[root@localhost ~]# kill -15 7104

再次使用      ps -ef|grep mysqld       确认mysql已经被杀死 


开启mysql,如下:

[root@localhost ~]# mysqld_safe --skip-grant-tables &[1] 7566[root@localhost ~]# 2016-04-02T10:23:22.463266Z mysqld_safe Logging to '/opt/mysql/data/localhost.localdomain.err'.2016-04-02T10:23:22.514395Z mysqld_safe Starting mysqld daemon with databases from /opt/mysql/datamysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.11 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

修改mysql密码:注意!以前的password字段,在mysql5.7已经被改为了authentication_string。在password()函数里面输入你的新密码,记得加单引号哦。

mysql> UPDATE mysql.user SET authentication_string=password('YourPassword') WHERE User='root'  AND Host='localhost';


好了,测试一下用新密码能不能进入:

[root@localhost ~]# mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.11Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

新密码修改成功!

一定要注意以前的password变成了authentication_string


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 脸擦破了痂掉了留斑怎么办 挤黑头后鼻子又红又疼怎么办 香奈儿邂逅清新淡香水不喷怎么办 脚面被压了肿起来了怎么办 每天加班很累反而失眠严重怎么办 减肥药吃了口臭嘴巴苦怎么办 上火引起的牙疼怎么办吃什么药 舌苔厚口气重怎么办应该吃什么药 宝宝老是额头热四肢不热怎么办 考老师考砸了心理崩溃了怎么办 苹果手机一会白屏一会黑屏怎么办 360云盘的东西删不了怎么办 手机邮箱打开的文件疑似病毒怎么办 电脑qq发送的文件失效了怎么办 小米4c温控文件打开是乱码怎么办 超星尔雅用学号登录密码忘了怎么办 全脸做激光去黄褐斑后脸发红怎么办 上传到微云中的视频下载不了怎么办 微云保存的小电影下载不了怎么办 苹果手机下载有云朵下载不了怎么办 手机下载登录忘了密码了怎么办 软软件被手机加密忘了密码怎么办 苹果手机想下载东西忘了密码怎么办 已经不念书几年了突然想上学怎么办 江湖风云录把王老爷子杀了怎么办 练扫踢胫骨旁边的肌肉受伤了怎么办 四个月宝宝没抱住摔了头部怎么办 老公老是跟年轻的小姑娘聊天怎么办 老婆出轨老公想离婚又舍不得怎么办 孕妇打完无痛分娩针就想睡觉怎么办 熟食店开空调菜品吹的很干怎么办 不锈钢锅在液化气烧了发黄怎么办 在小镇门面卤菜店不好卖怎么办? 被辣椒辣到嘴唇了该怎么办 沁园净水机不制水指示灯不亮怎么办 太辣了辣得胃疼怎么办 出现连接问题或mmi码无效怎么办 存折丢了怎么办卡号也不记得了 车内皮子被烂苹果腐蚀有印怎么办 锅被腐蚀后变黑色应该怎么办 后厨炉灶里的炉芯进水了怎么办