1.下载
https://mirrors.aliyun.com/mysql/MySQL-8.0/mysql-8.0.28-winx64.zip
2.文档
MySQL :: MySQL 8.0 Reference Manual :: 2.3.4 Installing MySQL on Microsoft Windows Using a noinstall ZIP Archive
3.创建配置文件my.ini。默认解压文件中没有
内容如下:
[mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] #设置3306端口 port = 3306 # 设置mysql的安装目录 basedir=E:/dev/mysql-8.0.28-winx64 # 设置mysql数据库的数据的存放目录 datadir=E:/dev/mysql-8.0.28-winx64/data # 允许最大连接数 max_connections=200 # 服务端使用的字符集默认为UTF8 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB |
4.初始化 datadir 目录,执行命令:
管理员cmd>E:\dev\mysql-8.0.28-winx64\bin\mysqld --initialize --console
E:\dev\mysql-8.0.28-winx64\bin>mysqld --initialize --console
2024-10-16T11:33:05.522472Z 0 [System] [MY-013169] [Server] E:\dev\mysql-8.0.28-winx64\bin\mysqld.exe (mysqld 8.0.28) initializing of server in progress as process 9696
2024-10-16T11:33:05.523839Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2024-10-16T11:33:05.601546Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-10-16T11:33:12.144023Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-10-16T11:33:30.739317Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: X1hcs-i%?teV
E:\dev\mysql-8.0.28-winx64\bin>
datadir目录会自动创建,下面会生成数据文件。还会在控制台打印随机生成的root密码。
如提示错误
说明没有安装VC++运行库,MySQL运行需要这个运行库,可以安装下面的运行时合集。
https://github.com/abbodi1406/vcredist/releases/download/v0.29.0/VisualCppRedist_AIO_x86_x64_29.zip
5.启动服务器
首次启动建议使用参数 --console,方便查看日志
E:\dev\mysql-8.0.28-winx64\bin\mysqld --console
日常启动,直接:mysqld
6.修改root密码
管理员cmd>
mysql -u root -p
mysql>
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
flush privileges;
7.停止 MySQL 服务器:
E:\dev\mysql-8.0.28-winx64\bin>E:\dev\mysql-8.0.28-winx64\bin\mysqladmin -u root -p shutdown
8.客户端连接报错:Public Key Retrieval is not allowed
原因:
mysql 8.0 默认使用 caching_sha2_password 身份验证机制 (即从原来mysql_native_password 更改为 caching_sha2_password。)
解决方法1:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
解决方法2:
客户端开启 或 数据库连接串 加上 allowPublicKeyRetrieval=true