- 开始-运行-regedit-回车,进入 Windows 注册表,然后找到[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MySQL]
- 修改 ImagesPath 项:
"C:\Program Files\MySQL\mysql-5.7.30-winx64\bin\mysqld" --defaults-file="C:\Program Files\MySQL\mysql-5.7.30-winx64\my.ini" MySQL
- 重启MySQL
cd C:\Program Files\MySQL\mysql-5.7.30-winx64\bin\
net stop mysql
net start mysql
如果有报错,是 my.ini 的内容有语法错误,请检查。
my.ini demo:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect='SET NAMES utf8mb4'
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir="C:\Program Files\MySQL\mysql-5.7.30-winx64"
datadir="C:\Program Files\MySQL\mysql-5.7.30-winx64\data"
port=3306
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size=128M
sort_buffer_size=16M
read_rnd_buffer_size=16M

- BTW: I Hate Windows.
Windows 安装 MySQL
- 解压到指定目录: C:\Program Files\MySQL\mysql-5.7.30-winx64
- 配置环境变量
变量名:MYSQL_HOME
变量值:C:\Program Files\MySQL\mysql-5.7.30-winx64
-
以管理员身份运行 cmd 生成 data 文件:
mysqld --initialize-insecure --user=mysql -
cmd:
mysqld -install -
PS: 安装时指定配置文件
my.ini:mysqld --install "MySQL" --defaults-file="C:\Program Files\MySQL\mysql-5.7.30-winx64\my.ini", 如果你的解压包中没有my.ini,你需要手动新建 -
启动服务:
net start mysql -
关闭服务:
net stop mysql -
登录:
mysql -u root -p