1、下載地址:https://dev.mysql.com/downloads/mysql/
2、解壓zip到安裝路徑
D:\Program_Files(本人安裝路徑)
3、新建配置文件my.ini(存儲在安裝目錄下的根目錄下,eg:D:\Program_Files\mysql-8.0.16-winx64\my.ini)
[mysqld]
# 設置3306端口
port=3306
# 設置mysql的安裝目錄
basedir=D:\Program_Files\mysql-8.0.16-winx64
# 設置mysql數據庫的數據的存放目錄
datadir=D:\Program_Files\mysql-8.0.16-winx64\Data
# 允許最大連接數
max_connections=200
# 允許連接失敗的次數。
max_connect_errors=10
# 服務端使用的字符集默認爲utf8mb4
character-set-server=utf8mb4
# 創建新表時將使用的默認存儲引擎
default-storage-engine=INNODB
# 默認使用“mysql_native_password”插件認證
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 設置mysql客戶端默認字符集
default-character-set=utf8mb4
[client]
# 設置mysql客戶端連接服務端時默認使用的端口
port=3306
4、初始化數據庫
以管理員身份運行cmd(注:必須以管理員身份),在C:\Windows\System32目錄下找到cmd.exe,進入在MySQL安裝目錄的 bin 目錄下執行命令:
mysqld --initialize --console
執行完成之後,會打印 root 用戶的初始默認密碼,比如:
D:\MySQL\mysql-8.0.13-winx64\bin>mysqld --initialize --console
- 2018-10-30T09:47:22.079528Z 0 [System] [MY-013169] [Server] D:\Program_Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server in progress as process 40936
- 2018-10-30T09:47:22.080771Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
- 2018-10-30T09:47:25.480866Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: f0,_wUSV!VuG
- 2018-10-30T09:47:26.882440Z 0 [System] [MY-013170] [Server]D:\Program_Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server has completed
注意:[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: f0,_wUSV!VuG 其中root@localhost:後面的“f0,_wUSV!VuG”就是初始密碼(不含首位空格)。在沒有更改密碼前,需要記住這個密碼,後續登錄使用。
如果沒記住,那也沒事,刪掉初始化的 datadir 目錄,再執行一遍初始化命令,又會重新生成的。當然,也可以使用安全工具,強制改密碼,用什麼方法,自己隨意。
5、安裝服務
在MySQL安裝目錄的 bin 目錄下執行命令(以管理員身份打開cmd命令行):
mysqld --install [服務名]
後面的服務名可以不寫,默認的名字爲 MySQL。當然,如果你的電腦上需要安裝多個MySQL服務,就可以用不同的名字區分了,比如 mysql1 和 mysql2。
安裝完成之後,就可以通過命令net start mysql啓動MySQL的服務了。
-
- D:\Program_Files\mysql-8.0.16-winx64\bin>mysqld --install
- Service successfully installed.
- D:\Program_Files\mysql-8.0.16-winx64\bin>net start
- mysqltest1 服務正在啓動 .mysqltest1 服務已經啓動成功。
- D:\Program_Files\mysql-8.0.16-winx64\
6、更改密碼
修改密碼:
登錄服務器,輸入:
mysql -uroot -p
提示輸入密碼:密碼在四中的初始化數據庫之後,[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: f0,_wUSV!VuG,其中的“ f0,_wUSV!VuG”爲默認密碼;
輸入如下命令,其中的“123456”爲我的密碼:
ALTER USER 'root'@'localhost' IDENTIFIED BY "123456";
如下:
D:\Program_Files\mysql-8.0.16-winx64\bin>mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.16
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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> ALTER USER 'root'@'localhost' IDENTIFIED BY "123456";
Query OK, 0 rows affected (0.06 sec)
mysql>
截止目前,默認密碼修改完畢;可使用SQLyog、Navicat等客戶端進行登錄使用;