Windwos安装解压版MySQL记录

系统版本:Windows Sever 2016 Standard

MySQL版本:5.7.30

1、将压缩包解压缩到安装目录

C:\Program Files\MySQL 下,并确保当前用户对MySQL目录有完全控制的权限。

2、配置环境变量

  • MySQL_HOME=C:\Program Files\MySQL
  • 在用户Path变量中追加%MySQL_HOME%\bin;

3、初始化数据库

MySQL目录下创建my.ini文件,确保后缀名为.ini,加入配置

注意如果指定的datadir,还有上级目录需确保上级目录存在,例如文中的情况,目录只需要存在D:\Data\就可以了,MySQL在初始化时会自动生成

[mysqld]
basedir=C:\Program Files\MySQL
datadir=D:\Data\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.

4、启动/关闭服务

#启动
mysqld --console
#关闭
mysqladmin -u root -p shutdown

服务器完成启动顺序后,您应该看到类似以下内容,这表明服务器已准备好为客户端连接提供服务

mysqld: ready for connections
Version: '5.7.31'  socket: ''  port: 3306

5、初始化root密码

先以root不使用密码的方式连接

mysql -u root --skip-password

分配密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';

6、安装MySQL服务(可选)

安装完成后,可以使用net start/stop mysql,方式控制MySQL服务的启动和关闭,执行此命令需要打开Admin cmd

MySQL代表安装服务的名称,可自行修改,需要进入MySQL\bin的绝对路径下执行安装命令,不然在使用net start MySQL时会报错

cd %MySQL_HOME%\bin
mysqld.exe --install MySQL

官方文档链接:https://dev.mysql.com/doc/refman/5.7/en/windows-install-archive.html

posted @ 2020-05-21 16:57  dwdh  阅读(305)  评论(0编辑  收藏  举报