下载mysql
https://dev.mysql.com/downloads/mysql/
image.png
image.png
解压下载好的mysql文件
image.png
创建my.ini文件
在解压后的目录下创建my.ini文件
[mysqld]
# 设置安装目录
basedir=D:/App/Dev/MySQL/mysql-8.0.12-winx64
# 设置数据目录
datadir=D:/App/Dev/MySQL/mysql-8.0.12-winx64/data
初始化数据目录
Microsoft Windows [版本 10.0.17134.285]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\Users\admin>cd D:\App\Dev\MySQL\mysql-8.0.12-winx64
C:\Users\admin>d:
D:\App\Dev\MySQL\mysql-8.0.12-winx64>bin\mysqld --initialize --console
2018-09-15T06:14:13.070756Z 0 [System] [MY-013169] [Server] D:\App\Dev\MySQL\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as process 23008
2018-09-15T06:14:16.878185Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 6su#s-J1sps9
2018-09-15T06:14:18.256858Z 0 [System] [MY-013170] [Server] D:\App\Dev\MySQL\mysql-8.0.12-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server has completed
D:\App\Dev\MySQL\mysql-8.0.12-winx64>
将mysql添加到windows服务
以管理员身份运行cmd并执行以下命令
D:\App\Dev\MySQL\mysql-8.0.12-winx64>bin\mysqld --install
Service successfully installed.
启动mysql服务
以管理员身份运行cmd并执行以下命令
D:\App\Dev\MySQL\mysql-8.0.12-winx64>net start MySQL
连接mysql
使用在初始化数据目录中得到随机生成的密码登陆
D:\App\Dev\MySQL\mysql-8.0.12-winx64>bin\mysql -uroot -p6su#s-J1sps9
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.12
Copyright (c) 2000, 2018, 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>
修改密码
mysql> alter user 'root'@'localhost' identified by 'MyPassword@123';
Query OK, 0 rows affected (0.06 sec)
关闭mysql服务
以管理员身份运行cmd并执行以下命令
D:\App\Dev\MySQL\mysql-8.0.12-winx64>net stop MySQL
添加到环境变量
C:\Users\admin>setx PATH "%PATH%;D:\App\Dev\MySQL\mysql-8.0.12-winx64\bin"
成功: 指定的值已得到保存。
MySQL官方参考文档
https://dev.mysql.com/doc/refman/8.0/en/windows-install-archive.html