1. 訪問搜狐鏡像 http://mirrors.sohu.com/mysql/MySQL-5.7/ 下載 mysql-5.7.23-winx64.msi
2. 安裝 mysql-5.7.23-winx64.msi ,選擇custom方式安裝,就可以選擇安裝路徑,否則默認安裝在C盤,然后一路 next 。
3. 進入 mysql 安裝目錄:
此時你可能會發現兩個問題:一是沒有my.ini文件,二是沒有data文件夾;
3.1 若沒有my.ini文件,則自己創建個my.ini文件,將以下內容Copy進去

1 # For advice on how to change settings please see 2 # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html 3 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the 4 # *** default location during install, and will be replaced if you 5 # *** upgrade to a newer version of MySQL. 6 [client] 7 default-character-set = utf8 8 [mysql] 9 default-character-set = utf8 10 [mysqld] 11 character-set-client-handshake = FALSE 12 character-set-server = utf8 13 collation-server = utf8_bin 14 init_connect='SET NAMES utf8' 15 # Remove leading # and set to the amount of RAM for the most important data 16 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 17 innodb_buffer_pool_size = 128M 18 # Remove leading # to turn on a very important data integrity option: logging 19 # changes to the binary log between backups. 20 # log_bin 21 # These are commonly set, remove the # and set as required. 22 basedir = D:\mysql 23 datadir = D:\mysql\data 24 port = 3306 25 # server_id = ..... 26 # Remove leading # to set options mainly useful for reporting servers. 27 # The server defaults are faster for transactions and fast SELECTs. 28 # Adjust sizes as needed, experiment to find the optimal values. 29 join_buffer_size = 128M 30 sort_buffer_size = 16M 31 read_rnd_buffer_size = 16M 32 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
注意,my.ini文件中的路徑,要修改為你的安裝路徑:
3.2 不要新建 data 文件夾(千萬不要自己手動建data文件夾,否則服務啟動不起來)
4.以管理員身份運行cmd
5.進入 bin 下
6. 執行: mysqld --initialize-insecure --user=mysql
接着執行:mysqld --install mysql --defaults-file=d:\mysql\my.ini
( 此時 mysql為你的服務名,你也可以修改為你定義的名稱 已經注冊成 windows的系統服務 )
接着執行:net start mysql
( 或進入 "服務"手動開啟 )
執行此句后,你可能會遇到服務啟動不起來的情況,此時參考如下操作:
https://blog.csdn.net/fan_lulu/article/details/82011994
7. 初始密碼在:你手動創建的data文件夾中,err文件內:
8.若密碼為空,則輸入:mysql -u root -p ,此時不輸入密碼,不輸入密碼,直接回車。便可進入mysql。
若密碼不為空,則執行 mysql -uroot -p 輸入初始密碼(上一步中控制台已經打印出來了 ,形如: localhost: <Bp(=fF4cAdJ)
9.重置密碼: alter user 'root'@'localhost' identified by 'root';,這樣就將密碼設置為了 root;
10.執行:mysql -u root -p ,回車后,輸入密碼 root,再次試試登錄,如果登錄成功,則完成mysql的安裝。
參考:
https://blog.csdn.net/heshiyuan1406146854/article/details/102745031,
https://blog.csdn.net/fan_lulu/article/details/82011994;
https://www.cnblogs.com/RayWang/p/9347874.html