MySQL 5.7.9 (64位)解压版正确修改默认密码
首先在mysql.zip解压后你会发现相比老版本,5.7.9版本目录下是没有data目录的,我们可以通过命令去生成一个这样的data文件。
但是在敲命令之前我们先把mysql的 .ini 文件配置一下,东西不多,在最下面添加以下代码:
port=3306
basedir=D:\dev\mysql\mysql-5.7.9-winx64
datadir=D:\dev\mysql\mysql-5.7.9-winx64\data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
这里注意里面的路径按照自己的来,然后把my-default.ini文件名改成my.ini
(注意:这里添加字段里面我发现有一个坑,网上有的博客会让你添加这样一段: default-character-set=utf8,结果会报错,提示你这个字段找不到的哈)。
然后我们就通过敲命令生成一个data文件,并把mysql的默认密码显示出来:
命令:mysqld --initialize --user=mysql --console
可以看到图上的最后一行的最后一个字段"ADT***t=R"是mysql的默认密码;可以进到自己的mysql解压目录下面看看文件结构有什么变化,我的是这样的:(仅供参考)
多了一个data文件(这个当然也可以手动删除,废话,我真是话多。。。)
接下来我们就先用这个默认密码登录到mysql里面,当然前提是要先start mysql;
命令:net start mysql
正常情况会提示你启动成功,(注意:有的会报无法启动3534,这是因为目录下面没有data文件,这个时候你要先用第一条命令init一下);
接着第二条命令,我们登录mysql:
命令:mysql -uroot -p
会提示你输入密码,就是上面我们看到的默认密码,输入后正常情况下会有welcome等提示
到这里我们就可以开始去修改我们的默认密码了,接着输入:
命令:use mysql
然后会提示你:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
不要急,我们接着输入命令:
命令:alter user 'root'@'localhost' identified by 'mysql';
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA24AAAA8CAYAAAAe/+kGAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA4CSURBVHhe7d0Bkts4DoXhzJ5sjj432w1656UQBCRIkbSk5P+qPGkTBAhR7rZUnXH++vbt23+/P273zz//fP35999/f/0ZVXH0sX8AAADAe/31/YL+lxs3f3EfL/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WLs5aF38tWsvnjq7vc/2frfw4X7R2HB812u9u/njsa/Xvx7Oxp/L9Zk7Hr6r2VvEW9XU1v4q3+DVHXh+9Hk0rrrGrfQIAAODff8ft/1/mF1j+QszG45x4odbKNdWFW7b+iNijZOPZGq38ET5XRmvE3CyvmuOPx38tI2v0+Py4RlV7ZO3dNWbzY66eZ+tUsty4vql68Kr8kfo9Mb9a/2p8picAAAD86seNW3UBdtpdF3hcWAIAAAB4up9+4/Zpd98sAgAAAMAb3HrjBgAAAACoLf07bgAAAACA87hxAwAAAIBH+/btf7mhH6zM1gY/AAAAAElFTkSuQmCC" alt="" />
然后会提示你Query OK !.
下面就正式进行修改我们的密码,这里有一个地方需要注意,5.7.9版本user表里面已经没有password这个字段了,可以看一下
但是这里有一个加密的 authentication_string 字段,这就是新版本的密码了,既然找到了我们就不客气了,改密码:
update user set authentication_string="Jb123456" where user="root";
然后我们查看一下,基本正常:
注意:这里很多人都会以为设置好了,就直接敲命令:flush privileges;然后退出重启登录了,结果会发现设置的密码不管用,楼主也是在这边吃了暗亏,停了有段时间不得其解,百度过后发现需要再设置以下:
SET PASSWORD = PASSWORD('yourPwd');
PASSWORD 后面写你刚刚设置过的新密码;
这次我们可以flush了:
flush privileges;
然后exit:
exit
我们看图说话:
这样我们就成功设置我们的新密码了。
好了,我们来验证一下,我是继续在开出的cmd命令窗口输入:
mysql -uroot -p
然后输入密码 (你的新密码),正常情况下就OK了。
如果还有什么问题,就先按照我这个步骤一步步慢慢来吧,有什么问题可以讨论一下。最后上一张全图:
到此结束。