1. 判斷本地是否已經安裝MySQL
① 在運行界面輸入services.msc進入服務界面,查看是否有MySQL服務


② 進入任務管理器,點擊服務看是否有MySQL服務

2. 安裝MySQL(壓縮包版)
1. 下載MySQL社區服務器(ZIP):
MySQL zip下載

點擊No thanks,just start my download就好,然后開始下載,保存檔案
2. 解壓檔案,建議保存到C盤以外的盤幅,在檔案夾里新建txt檔案,將my.txt檔案后綴名改為my.ini

3. 編輯my.ini檔案
[mysqld]
# 設定 3306 埠
port=3306
# 設定 mysql 的安裝目錄
basedir=D:\mysql
# 設定 mysql 資料庫的資料的存放目錄
datadir=D:\mysql\data
# 允許最大連接數
max_connections=200
# 允許連接失敗的次數,這是為了防止有人從該主機試圖攻擊資料庫系統
max_connect_errors=10
# 服務端使用的字符集默認為 UTF8
character-set-server=utf8
# 創建新表時將使用的默認存盤引擎
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
注意:
# 設定 mysql 的安裝目錄
basedir=D:\mysql(必須為實際安裝路徑)
# 設定 mysql 資料庫的資料的存放目錄
datadir=D:\mysql\data(可根據自己的需要更改)
4. 配置環境變數


5. 以管理員身份運行cmd

6. cmd 安裝步驟
C:\WINDOWS\system32>d:
D:\>cd mysql
初始化data目錄,初始化陳述句:(file=修改為對應路徑,我的路徑為:D:\mysql\my.ini)
D:\mysql>mysqld --initialize-insecur
D:\mysql>mysqld --defaults-file=D:\mysql\my.ini --initialize –console
安裝mysql服務:
D:\mysql>mysqld -install
Service successfully installed.
D:\mysql>mysqld --initialize-insecure --user=mysql
啟動mysql服務:
D:\mysql>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功,
進入mysql,第一次登錄無需輸入密碼(我是這種情況,版本8.0.31,若所遇情況不同,可百度尋找解決辦法),enter password:直接回車
D:\mysql>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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.
成功登錄后,修改登錄密碼(ALTER USER 'root'@'localhost' IDENTIFIED BY '要設定的密碼';):
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '要設定的密碼';
Query OK, 0 rows affected (0.00 sec)
重繪權限:
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
退出mysql:
mysql> exit;
Bye
停止mysql服務:
D:\mysql>net stop mysql
MySQL 服務正在停止.
MySQL 服務已成功停止,
重新登錄mysql
D:\mysql>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功,
D:\mysql>mysql -u root -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql>
3. 卸載MySQL(壓縮包版)
①進入任務管理器,找到MySQL,右鍵關閉服務
②win+R進入運行,輸入sc delete mysql
③進入安裝的盤幅,洗掉mysql整個檔案夾
④進入高級系統設定,洗掉mysql相關環境變數
4.備注
遇到的問題:
若安裝MySQL時,運行 mysqld install 時出現一下情況:
The service already exists!
The current server installed:.....
解決方法:
以管理員身份進入命令列,輸入 sc query mysql ,查看是否有一個名為mysql的服務:

命令sc delete mysql,洗掉該mysql

若想采用MSI方式安裝MySQL,可參考:
MSI方式安裝MySQL及卸載方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/540258.html
標籤:其他
