Windows再安装一个不同版本的MySQL数据库

前言:

在实际开发中,由于个人习惯和团队开发可能使用数据库的版本不一样,一些低版本数据库,不支持一些特殊的sql语句,因此高版本数据库数据导入低版本的时候就会出问题,因此,在一些特殊情况下,低版本数据库不能动,高版本mysql数据又无法导入低版本mysql,我们不得不在同一台机器上安装两个版本mysql.

正文:

此处演示同时安装MySQL8.0.16和MySQL5.7.22

1、进入MySQL官网:

https://dev.mysql.com/downloads/mysql/

选择MySQL Community Server,再选择Archived versions

2、选择版本

在列表里再次选择MySQL Community Server后,在版本选择页面选择我们需要的版本及匹配的电脑位数,点击右边的下载按钮,等待下载。最新版本在首页步骤1界面下拉即可看到并下载。

3、解压文件

下载完成后,将zip解压到相应的目录,这里笔者放在D:\Program Files\mysql\mysql-8.0.16-winx64和D:\Program Files\mysql\mysql-5.7.22-winx64下

4、配置MySQL配置文件

在步骤3的两个目录文件夹下创建文本文档my.txt,将文档后缀名改为.ini,在弹出框中选择“是”。

在配置文件里添加如下基本信息

mysql-8.0.16-winx64  ☟

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
 
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=D:\\Program Files\\mysql\\mysql-8.0.16-winx64
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
# datadir=D:\\Program Files\\mysql\\data
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#默认身份验证插件
default_authentication_plugin=mysql_native_password
#
explicit_defaults_for_timestamp=true

mysql-5.7.22-winx64  ☟

注意需要修改端口号

[mysql]
# 设置mysql客户端默认字符集
port = 3307
default-character-set=utf8
 
[mysqld]
# 设置3307端口
port = 3307
# 设置mysql的安装目录
basedir=D:\\Program Files\\mysql\\mysql-5.7.22-winx64
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
datadir=D:\\Program Files\\mysql\\mysql-5.7.22-winx64\\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#
explicit_defaults_for_timestamp=true
#
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

 5、先安装MySQL8.0.16

以管理员身份打开cmd命令行工具,切换目录

cd D:\Program Files\mysql\mysql-8.0.16-winx64\bin

 

初始化数据库 ,会在解压目录下生成data文件夹,

D:\Program Files\mysql\mysql-8.0.16-winx64\bin> mysqld --initialize --console

执行完成后,会输出root用户的初始默认密码: APWCY5ws&hjQ

...
..[Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ
...

或者在 data目录下找到后缀为.err的文件打开也可找到如上图初始密码

输入安装命令,因为需要安装两个数据库,需要命名区分

D:\Program Files\mysql\mysql-8.0.16-winx64\bin> mysqld install MySQL8

安装成功后提示:


Service successfully installed.

启动数据库,修改密码

D:\Program Files\mysql\mysql-8.0.16-winx64\bin> net start mysql8
MySQL8 服务正在启动 .
MySQL8 服务已经启动成功.

使用初始默认密码登录

D:\Program Files\mysql\mysql-8.0.16-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

修改密码:(注意分号)

set password for root@localhost=password('123456');

若出现操作错误,尝试用:

alter user root@localhost identified by '123456';


mysql> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

使用quit退出,使用新密码登录


mysql> quit
Bye

D:\Program Files\mysql\mysql-8.0.16-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

退出服务

D:\Program Files\mysql\mysql-8.0.16-winx64\bin>net stop mysql8
MySQL8 服务正在停止.
MySQL8 服务已成功停止。

至此,MySQL8.0.16安装完成。

6、安装MySQL5.7.22

重新以管理员身份运行cmd窗口

前提,MySQL8的服务已经关闭

切换目录

cd D:\Program Files\mysql\mysql-5.7.22-winx64\bin

 

初始化数据库 ,会在解压目录下生成data文件夹,

D:\Program Files\mysql\mysql-5.7.22-winx64\bin> mysqld --initialize --console

执行完成后,会输出root用户的初始默认密码: APWCY5ws&hjQ

...
..[Server] A temporary password is generated for root@localhost: APWCY5ws&hjQ
...

或者在 data目录下找到后缀为.err的文件打开也可找到如上图初始密码

输入安装命令,因为需要安装两个数据库,需要命名区分

D:\Program Files\mysql\mysql-5.7.22-winx64\bin> mysqld install MySQL5

安装成功后提示:


Service successfully installed.

启动数据库,修改密码

D:\Program Files\mysql\mysql-5.7.22-winx64\bin> net start mysql5
MySQL5 服务正在启动 .
MySQL5 服务已经启动成功.

使用初始默认密码登录

D:\Program Files\mysql\mysql-5.7.22-winx64\bin>mysql -u root -p
Enter password: ******
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

D:\Program Files\mysql\mysql-5.7.22-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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>

修改密码:(不要忘记分号)

set password for root@localhost=password('123456'); 

若出现操作错误,尝试用:

alter user root@localhost identified by '123456';


mysql> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

使用quit退出,使用新密码登录


mysql> quit
Bye

D:\Program Files\mysql\mysql-5.7.22-winx64\bin>mysql -u root -p
Enter password: ******
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

D:\Program Files\mysql\mysql-5.7.22-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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>

退出服务

D:\Program Files\mysql\mysql-5.7.22-winx64\bin>net stop mysql5
MySQL5 服务正在停止.
MySQL5 服务已成功停止。

至此,MySQL5.7.22也安装完成。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值