https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.14-winx64.zipC:\Program Files\MySQL\MySQL Server 5.7D:\MySQL\Data D:\MySQL\Log
[client] no-beep port=3306 [mysqld] server-id=45 port=3306 character-set-server=utf8mb4 pid-file="mysql.pid" basedir="C:\Program Files\MySQL\MySQL Server 5.7" datadir="D:/MySQL/Data" tmpdir="D:/MySQL/Data" default-storage-engine=INNODB # 慢查詢日誌 slow-query-log=1 long_query_time=1 slow_query_log_file="D:/MySQL/Log/mysql-slow.log" # 錯誤日誌 log-error="D:/MySQL/Log/mysql-error.log" # Binlog(按需開啟) # log-bin="D:/MySQL/Log/mysql-bin"
cd "C:\Program Files\MySQL\MySQL Server 5.7\bin" mysqld --defaults-file=C:\my.ini --initialize --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp
--initialize:生成隨機 root 密碼,**記錄在錯誤日誌** (mysql-error.log) 中。--initialize-insecure:生成無密碼 root(不推薦生產)。系統變數 Path 追加:C:\Program Files\MySQL\MySQL Server 5.7\bin
mysqld install MySQL --defaults-file="C:\my.ini" # 移除:mysqld remove MySQL
net start MySQL net stop MySQL
D:\MySQL\Log\mysql-error.log 獲取隨機密碼(如 2016-08-18T10:20:16.123456Z 0 [Note] A temporary password is generated for root@localhost: xYz#123Abc)。mysql -u root -p 輸入隨機密碼登錄。-- 方式 1
SET PASSWORD = PASSWORD('NewPass123!');
-- 方式 2 (5.7.6+ 推薦)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass123!';
官方初始化說明:Data Directory Initialization