本文记录一下Windows下的MySQL的安装过程,需要教程的自取。
当前系统环境:Windows 10
,MySQL最新版本:8.0.19
下载与解压
- 访问MySQL官方下载页面
- 此时页面会根据浏览器的UA自动定位操作系统。Windows环境下会自动定位到
Microsoft Windows
- 选择下载压缩包的安装版本:
Windows (x86, 64-bit), ZIP Archive
- … 等待下载 …
- 将下载好的压缩包解压到自己喜欢的位置,例如解压到
D:\Program Files\mysql-8.0.19-winx64
安装
- 以管理员打开命令行
- 进入到解压目录中的bin文件夹,如
D:\Program Files\mysql-8.0.19-winx64\bin
- 安装服务:
mysqld.exe install
- 初始化系统数据库:
mysqld.exe --initialize --console
,此处控制台会输出初始密码。 - 启动 mysql 服务:
net start mysql
C:\WINDOWS\system32>cd D:\Program Files\mysql-8.0.19-winx64\bin
C:\WINDOWS\system32>D:
D:\Program Files\mysql-8.0.19-winx64\bin>mysqld.exe install
Service successfully installed.
D:\Program Files\mysql-8.0.19-winx64\bin>mysqld.exe --initialize --console
2020-04-23T03:57:32.838774Z 0 [System] [MY-013169] [Server] D:\Program Files\mysql-8.0.19-winx64\bin\mysq1d.exe (mysq1d 8.0.19) initializing of server in progress as process 2058
2020-04-23T03:57:33.062512Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fapC%LfHqULO
2020-04-23T03:57:38.258426Z 0 [SystemJ [MY-013170] [Server] D:\Program Files\mysql-8.0.19-winx64\bin\mysq1d.exe (mysq1d 8.0.19) initializing of server has comp1eted
D:\Program Files\mysql-8.0.19-winx64\bin>net start mysql
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。
初次使用重置密码
- 使用
root
用户登录,输入上一步中控制台中输出的默认密码。 - 修改密码
D:\Program Files\mysql-8.0.19-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 921
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> alter user 'root'@'localhost' identified with mysql_native_password by 'mysql';
Query OK, 0 rows affected (0.15 sec)
mysql> exit
Bye
配置
修改解压目录下的 my.ini
文件,不存在则新建该文件。
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir= D:\ProjectTools\mysql-8.0.11-winx64
# 设置mysql数据库的数据的存放目录
datadir= D:\ProjectTools\mysql-8.0.11-winx64\data
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB