window 環(huán)境mysql8.0.4以上版本的安裝配置
- mysql 最新版下載:https://dev.mysql.com/downloads/mysql/
- 解壓zip包到指定路徑(E:\work\mysql\)
- 創(chuàng)建數(shù)據(jù)庫數(shù)據(jù)文件存放目錄(E:\cache\mysqldata\)
- 在安裝目錄(E:\work\mysql)下新建my.ini 或my-default.ini 文件:
[mysqld]
# 設(shè)置3306端口
port=3306
# 設(shè)置mysql的安裝目錄
basedir=E:\work\mysql
# 設(shè)置mysql數(shù)據(jù)庫的數(shù)據(jù)的存放目錄
datadir=E:\cache\mysqldata
# 允許最大連接數(shù)
max_connections=200
# 允許連接失敗的次數(shù)旋廷。這是為了防止有人從該主機(jī)試圖攻擊數(shù)據(jù)庫系統(tǒng)
max_connect_errors=10
# 服務(wù)端使用的字符集默認(rèn)為UTF8
character-set-server=utf8
# 創(chuàng)建新表時(shí)將使用的默認(rèn)存儲(chǔ)引擎
default-storage-engine=INNODB
# 默認(rèn)使用“mysql_native_password”插件認(rèn)證
default_authentication_plugin=mysql_native_password
[mysql]
# 設(shè)置mysql客戶端默認(rèn)字符集
default-character-set=utf8
[client]
# 設(shè)置mysql客戶端連接服務(wù)端時(shí)默認(rèn)使用的端口
port=3306
default-character-set=utf8
-
數(shù)據(jù)庫初始化
在bin目錄(E:\work\mysql\bin\)的路徑欄輸入cmd調(diào)起命令行窗口,
mysqld --initialize --console
執(zhí)行結(jié)果如下即表示成功:
E:\work\mysql\bin>mysqld --initialize --console
2019-05-15T09:37:51.704488Z 0 [System] [MY-013169] [Server] E:\work\mysql\bin\mysqld.exe (mysqld 8.0.16) initializing of server
in progress as process 7288
2019-05-15T09:37:51.715489Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the charac
ter set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-05-15T09:38:25.248407Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: iLDrqlh7q?iM
2019-05-15T09:38:34.596941Z 0 [System] [MY-013170] [Server] E:\work\mysql\bin\mysqld.exe (mysqld 8.0.16) initializing of server
has completed
其中root@localhost: iLDrqlh7q?iM
中iLDrqlh7q?iM
即為root賬戶初始密碼。更改密碼之前,此密碼最好記住
-
mysql服務(wù)安裝
mysqld --install
執(zhí)行結(jié)果如下即表示成功:
E:\work\mysql\bin>mysqld --install
Service successfully installed.
安裝時(shí)候由于之前版本卸載不完全造成失敗怎么辦
E:\work\mysql\bin>mysqld --uninstall
The service already exists!
The current server installed: E:\work\mysql5.7x64\bin\mysqld MySQL
這種情況可以使用命令sc query mysql
查看mysql服務(wù),并使用 sc delete mysql
刪除剧劝,然后再執(zhí)行mysqld --install
即可。
E:\work\mysql\bin>sc query mysql
SERVICE_NAME: mysql
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
E:\work\mysql\bin>sc delete mysql
[SC] DeleteService 成功
-
啟動(dòng)MySQL服務(wù)
net start mysql
執(zhí)行結(jié)果如下即表示成功:
E:\work\mysql\bin>net start mysql
MySQL 服務(wù)正在啟動(dòng) ....
MySQL 服務(wù)已經(jīng)啟動(dòng)成功。
-
修改初始密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密碼'
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.10 sec)
至此烦衣,mysql服務(wù)就已經(jīng)安裝、配置掩浙、啟動(dòng)好了花吟。
-
使用MySql Workbench操作數(shù)據(jù)庫
MySql Workbench中新建連接:
雙擊新建的連接,輸入密碼厨姚,即可進(jìn)入數(shù)據(jù)庫: