[mysql]windows下同时安装多个版本的mysql 5.6 5.7 8.0
MYSQL是目前最常用的数据库之一,因为历史项目维护、新项目环境启动等原因,有时需要同时使用多个版本的MYSQL,通常为了方便,我们会选择在本地搭建,本文主要介绍下如何windows下同时安装MYSQL 5.6 5.7 8.0 三个版本。### 下载
MySQL 官网```www.mysql.com/```
下载地址:```https://dev.mysql.com/downloads/mysql/```
下图是如何从官网找到真正下载的地方
!(data/attachment/forum/202206/30/114707ytputtvu53u63uht.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "mysql下载.gif")
如下图所示,我下载了免安装包
!(data/attachment/forum/202206/30/114745mimuunm33hamjahh.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 安装5.6
5.6 还是有自带默认配置文件的
1.) 管理员权限执行:
```html
mysqld --install MYSQL6
```
第三个参数省略的话,那就是默认为MYSQL了,既然安装多版本,还是取一个名字好
!(data/attachment/forum/202206/30/115250npqkwiiu8k7iqzvi.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
2.) 执行初始化
```html
mysqld --initialize
```
!(data/attachment/forum/202206/30/115320ob9hhzjh6yjyre09.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
3.)启动服务
```html
net start mysql
```
!(data/attachment/forum/202206/30/115341aecsr4zrral3peef.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
4.) 直接控制台登录
因为没有设置path ,所以此处是进入控制台进行打开
首次没有密码
!(data/attachment/forum/202206/30/115608hcn43dc05vddd272.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
使用dbeaver 进行连接,随便创建一个数据库,可以发现配置都是ok的,data文件夹下面有了数据
!(data/attachment/forum/202206/30/115628wahewese0aak6ema.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 5.7
1.) 新建配置文件
!(data/attachment/forum/202206/30/133149nb5dpbe44cseekcz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
内容如下:
```bash
# 设置mysql客户端默认字符集
default-character-set=utf8
#设置3306端口
port = 3307
# 设置mysql的安装目录
basedir=D:\ApplicationFiles\Programs\mysql-5.7.37-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\ApplicationFiles\Programs\mysql-5.7.37-winx64\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
```
2.)执行安装
如果执行安装报错,提示缺少运行库,可以进行下载
```html
https://www.microsoft.com/zh-CN/download/details.aspx?id=40784
```
!(data/attachment/forum/202206/30/133500awhwbktt20tjkaka.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
安装运行库后,继续重新安装
!(data/attachment/forum/202206/30/133713faiwntwyivp7viw1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
3.)继续执行初始化,可以看到data目录被创建
!(data/attachment/forum/202206/30/133730tipxxpq6z9q44qse.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
4.)启动
!(data/attachment/forum/202206/30/133801fepnpo998dqdlmsa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
5.)获取密码
从err日志中获取到密码
!(data/attachment/forum/202206/30/133934bxd5b8l16g666bu1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
6.)登录
!(data/attachment/forum/202206/30/133955xqqqa001qc30310w.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
7.)设置新密码
!(data/attachment/forum/202206/30/134037upa3rrvzyggr8g3g.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
```sql
#如果您有MySQL 5.7.6及更高版本或MariaDB 10.1.20及更高版本,请运行以下命令:
ALTER USER 'root'@'localhost' IDENTIFIED BY '这里填写你的新密码';
FLUSH PRIVILEGES;
#如果您有MySQL 5.7.5及更早版本或MariaDB 10.1.20及更早版本,请运行以下命令:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('这里填写你的新密码');
FLUSH PRIVILEGES;
```
客户端进行连接
!(data/attachment/forum/202206/30/134142edz4moyydtd3301y.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
### 5.8
5.8的安装与5.7类似,从新建配置文件开始,新建my.ini
```html
# 设置3308端口
port=3308
# 设置mysql的安装目录
basedir=D:\ApplicationFiles\Programs\mysql-8.0.29-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\ApplicationFiles\Programs\mysql-8.0.29-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
# 设置mysql客户端默认字符集
default-character-set=utf8
# 设置mysql客户端连接服务端时默认使用的端口
port=3308
default-character-set=utf8
```
初始化
!(data/attachment/forum/202206/30/134331mi24v71511llaxcl.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
启动服务
!(data/attachment/forum/202206/30/134341cdeq7zrpfh3sedg4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
根据日志获取临时密码
!(data/attachment/forum/202206/30/134400my09k69ddcp8996r.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
登录
!(data/attachment/forum/202206/30/134416wm3l63sswwwelwss.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
修改密码
!(data/attachment/forum/202206/30/134437pmm3gs1ccfkk4nz6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
客户端成功链接
!(data/attachment/forum/202206/30/134450va7w678wq6la69ql.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
!(data/attachment/forum/202206/16/141330jha7st9soow8772i.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "common_log.png")
`转载务必注明出处:程序员潇然,疯狂的字节X,https://www.crazybytex.com/thread-27-1-1.html `
页:
[1]