源码包下载
1.前往Mysql官网下载mysql Zip-Archive包(Windows X86-64位),本部署使用版本5.7.16。
下载地址:https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.16-winx64.zip
Mysql安装
1.将源码包解压到D:\mysql 目录,mysql的根目录为D:\mysql\mysql-5.7.16-winx64
2.将bin路径添加到环境变量path中。
部署Mysql实例
1.在根目录下创建data2文件夹
D:\mysql\mysql-5.7.16-winx64\data2
2.新建my2.ini文件,并做如下配置
[client]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3307端口
port = 3307
# 设置mysql的安装目录
basedir=D:\\mysql\\mysql-5.7.16-winx64
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
datadir=D:\\mysql\\mysql-5.7.16-winx64\\data2
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
3.打开cmd命令行并初始化
C:\Users\Administrator>mysqld --defaults-file=D:\mysql\mysql-5.7.16-winx64\my2.ini --initialize --console
2022-12-09T08:46:53.734024Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2022-12-09T08:46:55.311024Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-12-09T08:46:55.554024Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-12-09T08:46:55.729024Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 08f6dd00-779e-11ed-8ca6-a434d92ae2ba.
2022-12-09T08:46:55.738024Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-12-09T08:46:55.798024Z 1 [Note] A temporary password is generated for root@localhost: lZEyy*****
- Mysql的安装
C:\Users\Administrator>mysqld --install MySQL2 --defaults-file=D:\mysql\mysql-5.7.16-winx64\my2.ini
Service successfully installed.
5.Mysql的启动、连接和修改默认密码
C:\Users\Administrator>net start MySQL2
MySQL2 服务正在启动 .
MySQL2 服务已经启动成功。
C:\Users\Administrator>mysql -u root -P 3307 -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 Server version: 5.7.16
Copyright (c) 2000, 2016, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '#********';
Query OK, 0 rows affected (0.01 sec)
Mysql问题总结
此次mysql实例部署是在默认实例的基础上,又新增了一个实例,有以下几点需要注意:
1.部署新的Mysql实例,需要新建一个实例目录,本测试中为data2;
2.启动服务时,由于默认实例的名称为MySQL,我们新建的实例默认名为MySQL2,启动时需要注意区分;
3.新建实例的端口需要和默认端口不通,默认端口为3306,新建实例我们配置为3307.