1. 下载MySQL 8.0.16
官方链接可以直接下载 zip 压缩包
点击直接下载,不用登录。
2. 添加环境变量
找到解压后的bin目录,例:E:\MySQL\mysql-8.0.16-winx64\bin
配置到path下
3. 安装
PS:最新版本不需要创建data目录和my.ini文件
以管理员的身份cmd,或者右键win图标(电脑左下角)shell
进入解压后的bin目录下
- 初始化
PS E:\MySQL\mysql-8.0.16-winx64\bin> mysqld --initialize --console
2019-07-10T07:04:25.733237Z 0 [System] [MY-013169] [Server] E:\MySQL\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server in progress as process 10704
2019-07-10T07:04:31.181178Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 8o#NTgnu-lR)
2019-07-10T07:04:33.689908Z 0 [System] [MY-013170] [Server] E:\MySQL\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server has completed
第二行末尾root@localhost: 后面为临时随机密码
- 安装
PS E:\MySQL\mysql-8.0.16-winx64\bin> mysqld --install
Service successfully installed.
- 启动MySQL服务
PS E:\MySQL\mysql-8.0.16-winx64\bin> net start mysql
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。
- 登录(密码为上面初始化时候的密码)
PS E:\MySQL\mysql-8.0.16-winx64\bin> mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16
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>
5)修改临时默认密码
PS: 下面示例修改密码为:123456
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.03 sec)
6)退出
mysql> quit;
Bye