下載地址https://downloads.mysql.com/archives/community/
下載版本
下載后解壓,不包括data 和my.ini文件。其中data 文件是自動生成的【mysqld --initialize --console】,my.ini需要自己編寫設置。
新建my.ini文件
需要自己設置 basedir=G:\soft\mysql8 ,data也需要自己設置datadir=G:\soft\mysql8\data
[mysqld]
# 設置3306端口
port=3306
# 設置mysql的安裝目錄
basedir=G:\\soft\\mysql8
# 設置mysql數據庫的數據的存放目錄
datadir=G:\\soft\\mysql8\\data
# 允許最大連接數
max_connections=200
#允許連接失敗的次數。防止有人從該主機試圖攻擊數據庫系統
max_connect_errors=10
# 服務端使用的字符集默認為UTF8
#character-set-server=utf8
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
# 創建新表時將使用的默認存儲引擎
default-storage-engine=INNODB
# 默認使用“mysql_native_password”插件認證
default_authentication_plugin=mysql_native_password
[mysql]
# 設置mysql客戶端默認字符集
default-character-set=utf8
[client]
# 設置mysql客戶端連接服務端時默認使用的端口
port=3306
default-character-set=utf8
進入 cd \d G:\soft\mysql8\bin 執行 mysqld --initialize --console
出現以下報錯
2024-07-01T00:12:29.461863Z 0 [System] [MY-013169] [Server] G:\soft\mysql8\bin\mysqld.exe (mysqld 8.0.19) initializing of server in progress as process 25160
2024-07-01T00:12:29.462740Z 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-07-01T00:12:30.806628Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: T_+HbkvY9jro
–character-set-server: ‘utf8’ is currently an alias for the character set UTF8MB3 ,查閱資料需要設置
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
報錯的話 需要刪除data 目錄
重新執行
1.進入 cd \d G:\soft\mysql8\bin 執行 mysqld --initialize --console
成功
G:\soft\mysql8\bin>mysqld --initialize --console
2024-07-01T02:03:08.755838Z 0 [System] [MY-013169] [Server] G:\soft\mysql8\bin\mysqld.exe (mysqld 8.0.19) initializing of server in progress as process 33712
2024-07-01T02:03:10.112833Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Ao4lAdoVNk:J
- 執行mysqld install
G:\soft\mysql8\bin>mysqld install
Service successfully installed.
- 需要刪除服務(啟動跳過此步驟)
G:\soft\mysql8\bin>mysqld remove
Service successfully removed.
- 啟動服務
G:\soft\mysql8\bin>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功。
安裝成功了
5. 關閉服務
G:\soft\mysql8\bin>net stop mysql
MySQL 服務正在停止.
MySQL 服務已成功停止。
建議最好使用這個方式安裝,不使用gui的方式。可以方便調整參數和運維。
參考資料:http://www.imooc.com/wiki/mysqllesson/subaccount.html