windows同时安装MySQL5和MySQL8

一、下载压缩包

选择自己需要的版本,下载压缩包 即可。下载链接如下:

下载地址: https://dev.mysql.com/downloads/mysql/

二、解压缩安装

把压缩包解压出来,然后放到你自己想要的安装目录即可。 解压之后如下图:

三、编写 my.ini 配置文件

在安装目录新建 my.ini 文件, 具体内容如下:

[mysql]
default-character-set=utf8

[mysqld]
# 配置端口
port=3307

#Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/MoreDisks/Developer/Databases/MySQL8/"

#Path to the database root
datadir="C:/MoreDisks/Developer/Databases/MySQL8/data/"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# 启动 MySQL 时这里报错了 ==> Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
# Set the SQL mode to strict
# sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=200

# 自己添加的配置(也可以设置自己需要的大小)
max_allowed_packet=100M

四、命令启动 MySQL8

使用 win + x 打开快捷面板,点击 Windows PowerShel(管理员) ,此时进入到了一个蓝色窗口界面。然后按顺序执行如下代码:

# 建立默认数据库。小提示:建议在执行该条命令之前,在安装目录新建 data 文件夹,也就是上面的 datadir
mysqld --initialize-insecure --user=mysql

# 安装服务。我原先安装了 MySQL5.x 的版本,所以【MySQL】这个服务名就已经存在了,因此我把服务名定义为【MySQL8】
mysqld install MySQL8

# 启动 MySQL8 服务
net start MySQL8

五、登录 MySQL

先看一下截图。具体如下:

以下是上图的命令和结果。如下:

# 登录 MySQL。第一次登陆无需密码,因为安装的时候就没有设置密码(后期会贴图)
# 注意:这里要指定端口启动,我这里的端口号是 3307,因为 3306 端口被原先 MySQL5.x 版本占用了
# 注意:3307 端口号是来自 my.ini 配置文件中配置的那个端口号
mysql -uroot -P3307 -p

# 结果如下:
C:\Users\Jack>mysql -uroot -P3307 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 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.

# 修改密码:把 root 用户的密码修改成 1234
mysql> alter user 'root'@'localhost' identified by '1234';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 退出 MySQL 然后使用密码重新登陆即可
mysql> exit

六、删除系统服务

如果你在安装过程中出错了,想把 MySQL8 这个服务给删掉。 那就使用如下操作:

# 删除服务【出问题的情况下】。需要使用管理员打开 cmd 窗口进行操作,否则无效
sc delete MySQL8

# 删除服务之后会有提示删除成功或失败的信息

注意: 安装失败会在 data 目录下生成一个 xx.err 的错误日志, 可以根据该日志去解决相应的问题。

以下是我安装是出错的 错误日志(DESKTOP-US4O4GC.err) ,仅供参考:

2021-10-02T03:14:10.943968Z 0 [System] [MY-013169] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 7444
2021-10-02T03:14:10.947319Z 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-10-02T03:14:10.960692Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-10-02T03:14:11.378722Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-10-02T03:14:12.556759Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-10-02T03:21:12.341095Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:21:12.341586Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:/MoreDisks/Developer/Databases/MySQL8/Data/ is unusable. You can remove all files that the server added to it.
2021-10-02T03:21:12.343079Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:21:12.343351Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:22:27.111350Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:22:27.112664Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:22:27.112965Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:23:34.754407Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:23:34.755711Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:23:34.756034Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:24:21.441979Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:24:21.443304Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:24:21.443600Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:25:26.610676Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:25:26.611007Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:/MoreDisks/Developer/Databases/MySQL8/data/ is unusable. You can remove all files that the server added to it.
2021-10-02T03:25:26.612479Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:25:26.612745Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:25:31.365112Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:25:31.366210Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:25:31.366550Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:31:26.620990Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:31:26.621286Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:/MoreDisks/Developer/Databases/MySQL8/data/ is unusable. You can remove all files that the server added to it.
2021-10-02T03:31:26.622755Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:31:26.623024Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:32:08.016923Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:32:08.018082Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:32:08.018396Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:32:47.963390Z 0 [ERROR] [MY-000077] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Error while setting value 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2021-10-02T03:32:47.964959Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:32:47.965263Z 0 [Note] [MY-010120] [Server] Binlog end
2021-10-02T03:37:29.959269Z 0 [System] [MY-010116] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe (mysqld 8.0.25) starting as process 9228
2021-10-02T03:37:29.961316Z 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-10-02T03:37:29.976433Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-10-02T03:37:30.382525Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-10-02T03:37:30.536016Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2021-10-02T03:37:30.654135Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-10-02T03:37:30.654714Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-10-02T03:37:30.661157Z 0 [ERROR] [MY-000067] [Server] unknown variable 'query_cache_size=0'.
2021-10-02T03:37:30.662442Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-10-02T03:37:31.887063Z 0 [System] [MY-010910] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: Shutdown complete (mysqld 8.0.25)  MySQL Community Server - GPL.
2021-10-02T03:40:18.537738Z 0 [System] [MY-010116] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe (mysqld 8.0.25) starting as process 7516
2021-10-02T03:40:18.539668Z 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-10-02T03:40:18.553201Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-10-02T03:40:18.969226Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-10-02T03:40:19.133025Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2021-10-02T03:40:19.195539Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-10-02T03:40:19.196151Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-10-02T03:40:19.234700Z 0 [System] [MY-010931] [Server] C:\MoreDisks\Developer\Databases\MySQL8\bin\mysqld.exe: ready for connections. Version: '8.0.25'  socket: ''  port: 3307  MySQL Community Server - GPL.

七、出现的 BUG

当安装好 MySQL8 之后,使用 SQLyog 进行连接, 发现报了如下错误:

那么该如何解决呢?我参考了知乎的一篇文章,得到了解决方法【链接在文章底部】 。解决方法如下:

-- 1、错误提示:
Error No.1251
Client does not support authentication protocol requested by server;
consider upgrading MySQL client


-- 2、产生原因:
主要是由于 MySQL 以前的加密规则与 MySQL8 以后的存在差异,客户端和服务端版本差别太大


-- 3、解决办法:
1、使用 cmd 打开命令行窗口,然后连接到登录到 MySQL8 服务器进行数据库连接

2、登录成功之后,然后在 mysql> 后输入如下三条命令(下面三条命令一次输入一条,并按回车)
-- 修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; 
-- 更新一下用户的密码,password 为自己想要输入的密码例如 '123456'
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
-- 刷新权限
FLUSH PRIVILEGES;  

3、成功后在 SQLyog 中输入修改后的密码即可登录,搞定!!!

参考链接:
链接1 ==> sqlyog连接MySQL8.0出现Error No.1251
链接2 ==> 安装 mysql 遇到的坑(附 mysql 安装过程)

  • 文章作者:root
  • 创建时间:2022-01-15 07:33:19
  • 更新时间:2022-01-15 07:33:19
  • 版权声明:本文为博主原创文章,未经博主允许不得转载!
请 在 评 论 区 留 言 哦 ~~~
1024