具體步驟如下:
- 從官網(wǎng)下載對應(yīng)的版本。官方網(wǎng)址:mysql服務(wù)下載地址
- 解壓到本地。我的路徑是:D:\Program Files\mysql-5.7.16-winx64
- 設(shè)置環(huán)境變量。
- 添加一個系統(tǒng)變量。變量名:MYSQL_HOME,變量值是mysql的安裝目錄,我這里是:D:\Program Files\mysql-5.7.16-winx64
- 在Path變量中添加的末尾添加 ;%MYSQL_HOME%\bin
- 在安裝目錄下新建一個文本文檔,并改名為 my.ini,并添加如下內(nèi)容,保存。
[WinMySQLAdmin]
Server=D:\Program Files\mysql-5.7.16-winx64\bin\mysqld.exe
[mysqld]
basedir=D:\Program Files\mysql-5.7.16-winx64
datadir=D:\Program Files\mysql-5.7.16-winx64\data
port = 3306
server_id = 1
max_connections=1024
log_bin = mysql-bin
explicit_defaults_for_timestamp = TRUE
在安裝目錄下新建一個文件夾命名為data用來存放數(shù)據(jù)。
管理員身份進(jìn)入cmd執(zhí)x行初始化命令:mysqld --initialize --user=mysql --console
C:\Users\Administrator>mysqld --initialize --user=mysql --console
2016-12-07T07:29:17.384477Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-07T07:29:18.266527Z 0 [Warning] InnoDB: Creating foreign key constraint
system tables.
2016-12-07T07:29:18.648549Z 0 [Warning] No existing UUID has been found, so we a
ssume that this is the first time that this server has been started. Generating
a new UUID: dd3b2bf3-bc4e-11e6-8a79-6c0b8469263a.
2016-12-07T07:29:18.693552Z 0 [Warning] Gtid table is not ready to be used. Tabl
e 'mysql.gtid_executed' cannot be opened.
2016-12-07T07:29:18.727554Z 1 [Note] A temporary password is generated for root@
localhost: x>%B_fO)v1VV
產(chǎn)生一個隨機(jī)密碼,用記事本保存下來:x>%B_fO)v1VV
如果出現(xiàn)了以下警告:
2016-12-07T07:18:13.748519Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
檢查你的my.ini 中explicit_defaults_for_timestamp = TRUE是否配置正確
2016-12-07T07:18:13.749519Z 0 [ERROR] --initialize specified but the data direct
ory has files in it. Aborting.
這是前面安裝失敗導(dǎo)致D:\Program Files\mysql-5.7.16-winx64\data下產(chǎn)生了舊數(shù)據(jù),將舊數(shù)據(jù)刪掉即可。
- 輸入安裝命令:mysqld --install
C:\Users\Administrator>mysqld --install
Service successfully installed.
表示安裝成功
- 輸入啟動命令:net start MySQL
C:\Users\Administrator>net start MySQL
發(fā)生系統(tǒng)錯誤 2。
系統(tǒng)找不到指定的文件。
解決辦法:修改mysql注冊表。
開始-->運(yùn)行-->regedit-->HKEY_LOCAL_MACHINE-->SYSTEM-->CurrentControlSet-->services-->mysql(服務(wù)名)-->ImagePath
將ImagePath的路徑更改為:
"安裝目錄\bin\mysqld" --defaults-file="安裝目錄\my.ini" MySql
我這里是:
"D:\Program Files\mysql-5.7.16-winx64\bin\mysqld" --defaults-file="D:\Program Files\mysql-5.7.16-winx64\my.ini" MySql
更改后 服務(wù)成功啟動。
>MySql 服務(wù)正在啟動 .
MySql 服務(wù)已經(jīng)啟動成功。
-
輸入進(jìn)入mysql命令:mysql -u root -p
D:\Program Files\mysql-5.7.16-winx64\bin>mysql -u root -p
Enter password: 這里輸入第6步產(chǎn)生的隨機(jī)密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16-log
Copyright (c) 2000, 2016, 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>出現(xiàn)了mysql> 表示成功進(jìn)入到mysql
修改root用戶的初始密碼:set password for root@localhost = password('要修改的密碼');
mysql> set password for root@localhost = password('要修改的密碼');
Query OK, 0 rows affected, 1 warning (0.01 sec)
- 查看mysql數(shù)據(jù)庫:show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
參考文章:
http://jingyan.baidu.com/article/8cdccae946133f315513cd6a.html
http://blog.csdn.net/yanlintao1/article/details/52202736
http://www.oschina.net/question/727667_121198