一、MySQL官网下载对应版本的zip文件
最新版本8.0.32下载链接:https://dev.mysql.com/downloads/mysql/
![](https://img-blog.csdnimg.cn/img_convert/ba438e15f328f0321003816f06a3e8e4.png)
MySQL 5.7下载链接:https://downloads.mysql.com/archives/community/
![](https://img-blog.csdnimg.cn/img_convert/bf6ed10dfe16ccbc204964ca92463f3b.png)
二、将下载到的压缩包解压到指定目录
使用解压工具将下载到的压缩包解压:如:解压到H:/Download/目录下(自己选择),解压之后建议重命名该解压出来的文件:如mysql-8.0.32-winx64文件夹名,可将后面的winx64去掉,得到mysql-8.0.32(方便查看和理解,此处可不修改,但后续内容需对应更改)
![](https://img-blog.csdnimg.cn/img_convert/efd2ba014d81aeff69c8de0c2c56165e.png)
三、添加环境变量
右键我的电脑->属性->高级系统设置->环境变量
选择系统变量Path,在其后添加:你的mysql安装文件下面的bin文件夹
![](https://img-blog.csdnimg.cn/img_convert/48c3683bd541a151bab89ba1a5b9aeff.png)
![](https://img-blog.csdnimg.cn/img_convert/9650d3860c016b53f5b07482383ff37e.png)
四、在与bin同级的文件夹下新建,my.ini文件(注意:此处5.7版本和8.0版本操作不同)
![](https://img-blog.csdnimg.cn/img_convert/c4a2e911d75e3d9a11cb319cc2fc68eb.png)
编辑my.ini文件的内容(MySQL 5.7版本,路径改为自己电脑上对应的路径)
[mysqld]
basedir=H:\Download\mysql-8.0.23\
datadir=H:\Download\mysql-8.0.23\data\
port=3306
skip-grant-tables #免登陆检查
编辑my.ini文件的内容(MySQL 8.0版本,不需要加skip-grant-tables,路径改为自己电脑上对应的路径)
[mysqld]
basedir=H:\Download\mysql-8.0.23\
datadir=H:\Download\mysql-8.0.23\data\
port=3306
五、启动管理员模式下的CMD,并将路径切换至mysql下的bin目录,然后输入:mysqld -install(安装mysql)
1.启动管理员模式下的CMD
![](https://img-blog.csdnimg.cn/img_convert/2b325799870b97f252543442e4db80c4.png)
2.将目录切换到解压的mysql文件中的bin文件夹的位置:
输入:cd /d H:Download/mysql-8.0.32/bin/ (路径换为你电脑对应的位置即可)
![](https://img-blog.csdnimg.cn/img_convert/08e6a5fd898bd45b0e16ad9e20f06b0e.png)
3.此时输入:mysqld -install (安装mysql服务)
命令行界面出现:Service successfully installed. 即可
![](https://img-blog.csdnimg.cn/img_convert/3e8f354d4564c0079b2e06637c634fc8.png)
图中是已装了的情况。
六、再输入 mysqld --initialize-insecure --user=mysql初始化数据文件
输入之前目录如下:
![](https://img-blog.csdnimg.cn/img_convert/a2294c5716fd1ac5aed6150d273a56cb.png)
执行 mysqld --initialize-insecure --user=mysql (没输出ERROR信息则没报错)
![](https://img-blog.csdnimg.cn/img_convert/10d548fff7aca4adf8905565becfa22f.png)
![](https://img-blog.csdnimg.cn/img_convert/1e62fff01de8e08b2b72d04a7e28306e.png)
data文件夹,即为存储数据库的地方,之前有数据库可拷贝到该目录下就可以使用了。
![](https://img-blog.csdnimg.cn/img_convert/c6c0bf2453f8f6e4b97f462bfbd5f554.png)
七、启动mysql,然后用命令 mysql -uroot -p 进入mysql管理界面
控制台继续输入: net start mysql
![](https://img-blog.csdnimg.cn/img_convert/a2ba5bb10d131005bfe271e3c6a9aed8.png)
再输入: mysql -uroot -p
![](https://img-blog.csdnimg.cn/img_convert/15868b4c3d1599a0e0019cb1435c4804.png)
直接输入回车,就可以进入到mysql管理界面(因为我们没有密码)。
![](https://img-blog.csdnimg.cn/img_convert/a4065e55aff051f8c3d22faea8af01dc.png)
八、进入界面后更改root密码(注意:此处5.7版本和8.0版本操作不同)
1、mysql 5.7版本,输入:
update mysql.user set authentication_string='password(123456') where user='root' and host='localhost';
![](https://img-blog.csdnimg.cn/img_convert/f8f020c40d67bb387c4bfe9d08e48d81.png)
出现图上内容,则修改密码成功了。
2、mysql 8.0版本,依次输入:
use mysql;
ALTER user root@'localhost' identified by '123456';
![](https://img-blog.csdnimg.cn/img_convert/2833c70b325bb26937d25ac6955e0deb.png)
如图即修改成功。
最后两个版本都输入:flush privileges; 进行刷新权限。
![](https://img-blog.csdnimg.cn/img_convert/b7eab68455a67f5d2bb05d186b2e985a.png)
九、修改my.ini文件,删除最后一行skip-grant-tables免密登录(注意:此步只有5.7版本需要)
![](https://img-blog.csdnimg.cn/img_convert/90f4fc036ff51434b836d642bd992190.png)
十、重启mysql即可正常使用
![](https://img-blog.csdnimg.cn/img_convert/0ad7a61f67cb15f0ee6ec1332fb5ccdf.png)
十一、使用修改的密码登录mysql
![](https://img-blog.csdnimg.cn/img_convert/dc55455b19d79ede8d39dd4c48ee455a.png)