下載 mysql
下載頁面 MySQL :: Download MySQL Community Server
安裝 MySQL
下載完成之后,解壓 zip 包兄旬,再把整個解壓之后的結(jié)果放到 C 盤(其他盤也可以)裕偿。打開這個 MySQL 文件夾晃危,里面的文件如下圖所示:
配置 MySQL
新建 my.ini 文件:注意basedir和datadir 的路徑
[mysqld]
# 設(shè)置mysql的安裝目錄仓手,我們實際存放MySQL的目錄
basedir=C:\Program Files (x86)\mysql-8.0.32-winx64
# 設(shè)置mysql數(shù)據(jù)庫的數(shù)據(jù)的存放目錄
datadir=C:\Program Files (x86)\mysql-8.0.32-winx64\data
# 設(shè)置默認使用的端口
port=3306
# 允許最大連接數(shù)
max_connections=200
# 允許連接失敗的次數(shù)两嘴。這是為了防止有人試圖攻擊數(shù)據(jù)庫
max_connect_errors=10
# 服務(wù)端使用的字符集
character-set-server=utf8mb4
# 數(shù)據(jù)庫字符集對應(yīng)一些排序等規(guī)則使用的字符集
collation-server=utf8mb4_general_ci
# 創(chuàng)建新表時將使用的默認存儲引擎
default-storage-engine=INNODB
# 默認使用“mysql_native_password”插件作為認證加密方式
# MySQL8.0默認認證加密方式為caching_sha2_password
default_authentication_plugin=mysql_native_password
[mysql]
# 設(shè)置mysql客戶端默認字符集
default-character-set=utf8mb4
[client]
default-character-set=utf8mb4
port=3306
復(fù)制
bin目錄加入環(huán)境變量
初始化 MySQL
打開cmd歹嘹,快捷鍵“win+R”享甸,輸入cmd再回車截碴,即可打開cmd。執(zhí)行初始化命令枪萄,該命令會創(chuàng)建一個密碼為空的root用戶隐岛。
mysqld --initialize-insecure --user=mysql --console
復(fù)制
D:\mysql-8.0.32-winx64>mysqld --initialize-insecure --user=mysql --console
2023-02-27T06:33:22.062461Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-02-27T06:33:22.062480Z 0 [System] [MY-013169] [Server] D:\mysql-8.0.32-winx64\bin\mysqld.exe (mysqld 8.0.32) initializing of server in progress as process 49700
2023-02-27T06:33:22.081374Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-27T06:33:22.885540Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-02-27T06:33:24.034585Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
復(fù)制
執(zhí)行初始化命令成功之后,再執(zhí)行下面的命令瓷翻,安裝 mysql 服務(wù)(要管理員模式打開 命令行):
mysqld --install
復(fù)制
安裝服務(wù)成功之后聚凹,啟動服務(wù):
net start mysql
如果啟動失敗看看是不是my.ini的路徑問題
修改 root 用戶的密碼
上面步驟成功之后割坠,可以在 cmd 輸入如下命令進入MySQL:
mysql -u root -p
復(fù)制
輸入如下 SQL 語句,修改 root 用戶的密碼:
alter user 'root'@'localhost' identified by '你的密碼';
到此結(jié)束妒牙,祝大家前程似錦彼哼!
如果遇到如下情況:MySQL 服務(wù)無法啟動”,“請鍵入 NET HELPMSG 3523 以獲得更多的幫助”湘今。
第一步:先把mysqld進程殺死敢朱。執(zhí)行:
tasklist| findstr "mysql"
如果有mysqld進程,執(zhí)行:
taskkill/f /t /im mysqld.exe
殺死進程
第二步:到MySQL安裝目錄bin下摩瞎,執(zhí)行:
mysqld --console
完美解決:奧里給拴签。