MySQL Community 8 Windows zip 版安裝配置

下載 zip 文件

https://dev.mysql.com/downloads/mysql/

點擊下載
在這裏插入圖片描述

跳過登錄直接下載
在這裏插入圖片描述

安裝

解壓到

D:\DevTools\mysql-8.0.16-winx64

在這裏插入圖片描述
加入環境變量(可選)

新增 MYSQL_HOME
D:\DevTools\mysql-8.0.16-winx64

在這裏插入圖片描述

Path 累加 (ps:win10 可以不關注分號)
%MYSQL_HOME%\bin

在這裏插入圖片描述
在根目錄下面添加 my.ini文件,內容如下
裏面的 basedir 是本地的安裝目錄,datadir 是數據庫數據文件要存放的位置,可以自定義

[mysqld]
default_authentication_plugin=mysql_native_password
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = D:\DevTools\mysql-8.0.16-winx64
datadir = D:\DevTools\mysql-8.0.16-winx64\data
port = 3306
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

character-set-server = utf8mb4

performance_schema_max_table_instances = 600
table_definition_cache = 400
table_open_cache = 256

[mysql]
default-character-set = utf8mb4

[client]
default-character-set = utf8mb4

使用管理員身份 運行 CMD

注意!
不管是否設置了環境變量 都需要定位到根目錄的 bin 目錄下執行命令,否則會安裝出錯

發生系統錯誤 2。

所以定位到 bin 目錄下

cd /d D:\DevTools\mysql-8.0.16-winx64\bin

在這裏插入圖片描述
然後執行初始化命令

mysqld --initialize --console

如果沒有報錯的話會打印出臨時密碼

類似:

A temporary password is generated for root@localhost: 7Wvs#Ja9r5rz

記下該密碼

7Wvs#Ja9r5rz

繼續安裝服務,服務名可以省略 默認 mysql 安裝後的服務名 MySQL

mysqld --install  [服務名]

在這裏插入圖片描述
可以自定也 mysql5 或mysql8 這類的 以示區分

啓動

啓動 mysql 服務

net start mysql

在這裏插入圖片描述
登錄 mysql

mysql -u root -p

會讓你輸入剛纔記下的密碼


然後修改密碼爲 password 可以自定義

ALTER USER 'root'@'localhost' IDENTIFIED  BY 'password';

因爲 my.ini 配置了 default_authentication_plugin 使用 mysql_native_password 插件認證,如果沒配置
可以改用這個

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

提示 Query OK, 0 rows affected 代表修改成功
在這裏插入圖片描述
ps: 期間遇到問題可能會用到的命令

//windows 停止 mysql服務
net stop mysql
//卸載服務
mysqld -remove
//windows 刪除 mysql 服務
sc delete mysql

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章