一、安装包下载
1、下载地址:MySQL :: Download MySQL Community Server https://dev.mysql.com/downloads/mysql/
因为本次安装5.7版本,所以需要选归档下载:
3、下载完后解压放到安装目录 (本次是解压在C盘根目录)二、安装
1、配置环境变量
右键“此电脑”--“高级系统设置”--"环境变量" 新建系统变量
变量名:MysqL_HOME
变量值:C:\MysqL-5.7.35-winx64 (安装目录,以实际为准)
2、 创建及配置my.ini文件
5.7.35版本安装包默认已不带my.ini文件了,默认会在安装目录下生成data文件,如果安装目录又在系统盘就不好了,所以建议手动创建my.ini文件。在安装包根目录上创建my.ini文件,输入如下信息(可依需求自行更改):
[MysqL]
#Setting the default character set of MysqL client
default-character-set=utf8
[MysqLd]
#Set 3306 port
port = 3306
#Set MysqL installation directory
basedir=D:\\DB_files\\MysqL
#Maximum number of connections allowed
max_connections=200
#The character set used by the server is the 8-bit latin1 character set by default
character-set-server=utf8
#The default storage engine that will be used when creating a new table
default-storage-engine=INNODB
注意, 这里的目录是用双反斜杠(亲测有用),有的文章是写单反斜杠(本人未验证) 。
3、生成data文件
5.7.35默认也是没有data目录的,不建议手动创建data目录,建议由MysqL来生成。(有文章说自行创建data会报错)
以管理员身份运行cmd,进入安装包bin目录(C:\MysqL-5.7.35-winx64\bin,自行依实际目录更改)
执行命令:
MysqLd --initialize-insecure --user=MysqL
C:\MysqL-5.7.35-winx64\bin>MysqLd --initialize-insecure --user=MysqL
可以看到D:\DB_files\MysqL目录多了个data文件夹
4、开始安装服务
执行命令:
MysqLd --install
C:\MysqL-5.7.35-winx64\bin>MysqLd --install
Service successfully installed.
5、启动服务
执行命令:
net start MysqL
C:\MysqL-5.7.35-winx64\bin>net start MysqL
MysqL 服务正在启动 .
MysqL 服务已经启动成功。
6、登入验证
MysqL正常启动后,使用root登入进行验证(密码为空)
C:\MysqL-5.7.35-winx64\bin>MysqL -uroot -p
Enter password:
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 2
Server version: 5.7.35 MysqL Community Server (GPL)copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
7、更改密码
alter user root@localhost identified by '你的密码';
MysqL>alter user root@localhost identified by '你的密码';
Query OK, 0 rows affected (0.00 sec)
至此,MysqL已安装成功
三、问题解决
1、未配置my.ini文件,安装好后发现无处更改data目录
思路:卸载服务--创建my.ini文件--重新生成data目录
C:\MysqL-5.7.35-winx64\bin>net stop MysqL
MysqL 服务正在停止.
MysqL 服务已成功停止。
删除服务
创建my.ini文件(把data目录调整到其它位置)后,重新安装
C:\MysqL-5.7.35-winx64\bin>MysqLd --install
Service successfully installed.
启动服务
C:\MysqL-5.7.35-winx64\bin>net start MysqL
MysqL 服务正在启动 .
MysqL 服务已经启动成功。
参考文章:Windows下安装MySQL详细教程 - m1racle - 博客园 (cnblogs.com)https://www.cnblogs.com/zhangkanghui/p/9613844.htmlConfiguration of mysql5.7 or above my.ini Detailed steps for | Develop PaperProvide a platform for developers to answer questions, learn and exchange programming knowledge, and create an era that belongs to developers!https://developpaper.com/configuration-of-mysql5-7-or-above-my-ini-detailed-steps-for/