问题:

安装mysql时,在输入 mysqld --initialize --console 后报如下错误:

C:\mysql-8.0.25-winx64\bin>mysqld --initialize --console
2022-03-15T08:24:37.761280Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.25-winx64\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 13700
2022-03-15T08:24:37.762523Z 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.
2022-03-15T08:24:37.763353Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2022-03-15T08:24:37.763361Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:\mysql-8.0.25-winx64\data\ is unusable. You can remove all files that the server added to it.
2022-03-15T08:24:37.764389Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-03-15T08:24:37.764684Z 0 [System] [MY-010910] [Server] C:\mysql-8.0.25-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.25)  MySQL Community Server - GPL.

解决方案:

  1. 检查 my.ini 文件
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir= C:\mysql-8.0.25-winx64
# 设置mysql数据库的数据的存放目录
datadir= C:\mysql-8.0.25-winx64\data
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

  1. 删除 data 文件夹后重试

正确页面:

C:\mysql-8.0.25-winx64\bin>mysqld --initialize --console
2022-03-15T08:26:48.544270Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.25-winx64\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 34840
2022-03-15T08:26:48.545665Z 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.
2022-03-15T08:26:48.557204Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-15T08:26:49.240892Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-15T08:26:51.597757Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: gmDBifvep0!i
Logo

更多推荐