mysql 多版本安装_安装多个版本的MySQL

关闭 MySQL 5.5 的服务:win + r ---> services.msc ---> 在服务窗口中找到MySQL,停止其服务

下载 MySQL 8,网址如下:https://dev.mysql.com/downloads/mysql/,直接可下:

913c44254db50ad8b91297a9e20b2b7a.png

可以下载最新的吧,或者去https://downloads.mysql.com/archives/community/下载过往版本

我下载的是 8.0.13 不过现在已经不是最新的了

将下载的mysql-8.0.13-winx64.zip文件,解压到你需要安装的路径即可,如

C:\Software\MySQL8\mysql-8.0.13-winx64

把新安装的 MySQL8 加入环境变量

5f3362128d58347625e6966332ea9a11.png

编辑 MySQL8 的 my.init文件,若不存在则直接自己创建,如下:

例如,我刚刚的文件解压在C:\Software\MySQL8\mysql-8.0.13-winx64,在其内创建my.ini

下面的部分内容需要根据本地的配置进行相应修改

# 内容如下:

[mysqld]

# 设置3307端口,为了与旧版本的区分不冲突

port=3307

# 设置mysql的安装目录

# 切记此处一定要用双斜杠\\,单斜杠我这里会出错,不过看别人的教程,有的是单斜杠。自己尝试吧

basedir=C:\\Software\\MySQL8\\mysql-8.0.13-winx64

# 设置mysql数据库的数据的存放目录

datadir=C:\\Software\\MySQL8\\date

# 允许最大连接数

max_connections=200

# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统

max_connect_errors=10

# 服务端使用的字符集默认为UTF8

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

# MySQL8.0.4之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。

# 但因为当前有很多数据库工具和链接包都不支持“caching_sha2_password”,为了方便,暂时改回了“mysql_native_password”认证插件。

# 默认使用“mysql_native_password”插件认证

default_authentication_plugin=mysql_native_password

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

[client]

# 设置mysql客户端连接服务端时默认使用的端口

port=3307

default-character-set=utf8

初始化 MySQL,以管理员的身份运行cmd,如下:

# 进入如下目录:

C:\Windows\system32>cd C:\Software\MySQL8\mysql-8.0.13-winx64

# 运行如下命令:mysqld --initialize --console

C:\Software\MySQL8\mysql-8.0.13-winx64>mysqld --initialize --console

2021-01-25T13:10:56.200416Z 0 [System] [MY-013169] [Server] C:\Software\MySQL8\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server in progress as process 14848

2021-01-25T13:10:56.213381Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.

2021-01-25T13:11:01.188180Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ikYTWgn=y7q. # 记录此处的密码,后续登录需要使用

2021-01-25T13:11:02.342337Z 0 [System] [MY-013170] [Server] C:\Software\MySQL8\mysql-8.0.13-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server has completed

进入 bin 目录,运行如下:mysqld --install [服务名]

mysql 5.5 的服务器名为 MySQL,因此此处我起名为 MySQL8

C:\Software\MySQL8\mysql-8.0.13-winx64>cd bin

C:\Software\MySQL8\mysql-8.0.13-winx64\bin>mysqld --install MySQL8

Service successfully installed. # 成功安装

安装成功后,通过 win + r ---> services.msc ---> 在服务中找到新添加的服务 MySQL8

7b185827f9b28d1e102bdefe3100288d.png

继续在改终端下启动 mysql8,net start MySQL8,

C:\Software\MySQL8\mysql-8.0.13-winx64\bin>net start MySQL8

MySQL8 服务正在启动 .

MySQL8 服务已经启动成功。

其中 MySQL8 为上一步你起的服务名,还有如下相关命令:

启动服务:net start 服务名

关闭服务:net stop 服务名

重启服务:net restart 服务名

登录 mysql8 修改密码:继续在终端中,输入mysql -u root -p

C:\Software\MySQL8\mysql-8.0.13-winx64\bin>mysql -u root -p

Enter password: ************ # 这里的密码就是第6步:初始化mysql时的密码

# 注:手打没有打对过,因此在前面复制密码,然后在这里鼠标右击即可自动复制

# 连接成功!

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.13

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>

修改密码:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

Query OK, 0 rows affected (0.07 sec)

# 修改成功,MySQL8 也安装成功

SQLyog 连接,mysql8,如下:

c864720eb954b850b53d4a719da8d0bf.png

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值