系统版本:Windows Sever 2016 Standard
MySQL版本:5.7.30
将压缩包解压缩到安装目录
C:\Program Files\MySQL
下,并确保当前用户对MySQL目录有完全控制的权限。
配置环境变量
- MySQL_HOME=C:\Program Files\MySQL
- 在用户Path变量中追加%MySQL_HOME%\bin;
初始化数据库
MySQL目录下创建my.ini
文件,确保后缀名为.ini
,加入配置
注意D:\MySQL,此目录不要自己创建,如果指定的datadir,还有上级目录需确保上级目录存在
[mysqld]
basedir=C:\Program Files\MySQL
datadir=D:\MySQL
配置文件可选项参考下链接
https://dev.mysql.com/doc/refman/5.7/en/server-option-variable-reference.html
cmd执行命令,本次采用不生成root密码的方式
#不生成root密码
mysqld --initialize-insecure --console
#生成root密码
mysqld --initialize --console
出现如下图错误,参考:https://www.cnblogs.com/dwdh/p/12929325.html
出现以下内容表示初始化成功!
2020-05-21T06:59:01.587092Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-21T06:59:01.736719Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-21T06:59:01.795157Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-21T06:59:01.869607Z 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: 8d3d4709-9b30-11ea-9623-000c29082601.
2020-05-21T06:59:01.877243Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-21T06:59:03.256823Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-21T06:59:04.153132Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
启动服务
mysqld --console
服务器完成启动顺序后,您应该看到类似以下内容,这表明服务器已准备好为客户端连接提供服务
mysqld: ready for connections
Version: '5.7.31' socket: '' port: 3306
初始化root密码
先以root不使用密码的方式连接
mysql -u root --skip-password
分配密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
启动/关闭服务
#启动
mysqld --console
#关闭
mysqladmin -u root -p shutdown
安装MySQL服务(可选)
安装完成后,就可以使用net start/stop mysql,方式控制MySQL服务的启动和关闭了,执行此命令需要打开Admin cmd
mysql代表安装服务的名称,可自行修改,需要进入MySQL的绝对路径下执行安装,不然安装完在使用net start mysql命令时会报错
cd %MySQL_HOME%\bin
mysqld -install MySQL