一 mysql server 下載
官網下載地址頁面
https://dev.mysql.com/downloads/mysql/
二 免裝版使用步驟
1 解壓
下載完成后,解壓文件夾,如下所示:
2 執行安裝命令
D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin>mysqld --install
Service successfully installed.
3 初始化mysql
D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin>mysqld --initialize --console
2025-03-31T02:30:43.318917Z 0 [System] [MY-013169] [Server] D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin\mysqld.exe (mysqld 8.0.41) initializing of server in progress as process 8224
2025-03-31T02:30:43.344538Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-03-31T02:30:44.019707Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-03-31T02:30:46.985785Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: :W*Vd?:b123*
初始化會產生一個隨機密碼,在最后一行顯示,記住這個密碼,登錄會用到
4 開啟服務
D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功。
5 登錄
D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin>mysql -u root -h localhost -p
三 問題處理
在登錄時候,可能會遇到一個問題,如下:
D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin>mysql -u root -h localhost -p
Enter password: **
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解決步驟
# 關閉服務
net stop mysql# 通過控制臺跳過密碼表的加載和檢查操作(不要關閉此CMD頁面,另外以管理員身份打開CMD,然后輸入mysql -u root,如果要求輸入命令直接按Enter鍵跳過)
mysqld --console --skip-grant-tables --shared-memory
另外一個cmd窗口連接mqsql后,進行修改密碼
D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.41 MySQL Community Server - GPLCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)
五 服務開啟自啟
在安裝的bin目錄下執行命令
D:\soft\mysql\mysql-8.0.41-winx64\mysql-8.0.41-winx64\bin>sc config mysql start=auto
[SC] ChangeServiceConfig 成功