进入MySQL官方下载通道
https://dev.mysql.com/downloads/mysql/
选择合适的文件压缩包进行下载
解压缩到自己的文件目录之下,并创建一个my.ini文件和data文件夹
my.ini文件中写入如下配置信息
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:\DataBase\mysql
# 设置mysql数据库的数据的存放目录
datadir=C:\DataBase\mysql\data
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
wait_timeout=31536000
interactive_timeout=31536000
根据自己的文件路径对应修改mysql的安装目录和数据存放目录
使用管理员权限打开cmd命令行
进入MySQL文件的加压路径中的bin目录下
C:\Windows\system32>cd C:\DataBase\mysql\bin
C:\DataBase\mysql\bin>
输入初始化命令,等待计算机完成初始化
C:\DataBase\mysql\bin>mysqld --initialize --console
2019-04-30T09:09:37.144941Z 0 [Warning] option 'wait_timeout': unsigned value 31536000 adjusted to 2147483
2019-04-30T09:09:37.145007Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-30T09:09:38.036418Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-30T09:09:38.168897Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-30T09:09:38.276482Z 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: ae3ed429-6b27-11e9-8df0-54ee75abaec8.
2019-04-30T09:09:38.285992Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-30T09:09:38.293536Z 1 [Note] A temporary password is generated for root@localhost: fgHs(n37-elf
C:\DataBase\mysql\bin>
输入安装mysql的命令,完成安装
C:\DataBase\mysql\bin>mysqld -install
Service successfully installed.
C:\DataBase\mysql\bin>
启动MySQL服务
C:\DataBase\mysql\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
C:\DataBase\mysql\bin>
现在,MySQL已经安装完成并启动,可以进行登录操作
首次登录的密码是初始化时随机生成的密码,本次安装中生成的是 fgHs(n37-elf
C:\DataBase\mysql\bin>mysql -hlocalhost -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26
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>
笔者安装过程中,由于使用了之前的my.ini配置文件,在配置文件中启用了二进制日志,导致初始化失败
C:\DataBase\mysql\bin>mysqld --initialize --console
2019-04-30T09:07:33.533588Z 0 [Warning] option 'wait_timeout': unsigned value 31536000 adjusted to 2147483
2019-04-30T09:07:33.537527Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-30T09:07:33.656415Z 0 [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server start-up parameters documentation
2019-04-30T09:07:33.657652Z 0 [ERROR] Aborting
解决的方法很简单,只需要把my.ini文件中有关启用二进制日志的配置信息注释或者删除就可以了。
在具体的初始化和安装过程中,可能会出现各种形式的问题,但是一定会有相应的报错信息,根据报错信息是很容易找到原因并解决的。