一、安装包下载
1、下载地址:MySQL :: Download MySQL Community Serverhttps://dev.mysql.com/downloads/mysql/2、选择对应版本
因为本次安装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.
mysql>
7、更改密码
因为默认密码是空,不安全,建议对root用户进行更改密码;
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 服务已成功停止。
删除服务
C:\mysql-5.7.35-winx64\bin>sc delete 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/