參考官方文檔
http://dev.mysql.com/doc/refman/5.7/en/windows-install-archive.html
2.3.5.1 Extracting the Install Archive
下載路徑:http://dev.mysql.com/downloads/mysql/
解壓到自定義路徑,如D:\Program Files\mysql-5.7.12-winx64
2.3.5.2 Creating an Option File
新建data文件夾,路徑如下:D:\Program Files\mysql-5.7.12-winx64\data(若不想用data而是mydata詳見官方文檔)
D:\Program Files\mysql-5.7.12-winx64目錄下新建my.ini文件(或直接修改my-default.ini):
[mysqld]
basedir = D:\Program Files\mysql-5.7.12-winx64
datadir = D:\Program Files\mysql-5.7.12-winx64\data
port = 3306
在系統變量中配置
MYSQL_HOME=D:\Program Files\mysql-5.7.12-winx64;
path新增%MYSQL_HOME%\bin;
以管理員身份運行cmd(一定要用管理員身份運行,不然權限不夠),
輸入:cd C:\Program Files\MySQL\MySQL Server 5.6\bin 進入mysql的bin文件夾(不管有沒有配置過環境變量,也要進入bin文件夾,否則之後啟動服務仍然會報錯誤2)
輸入mysqld -install(如果不用管理員身份運行,將會因為權限不夠而出現錯誤:Install/Remove of the Service Denied!)
2.3.5.3 Selecting a MySQL Server Type
略(可直接跳過)
2.3.5.4 Initializing the Data Directory
On Windows, use one of these commands:
C:\>bin\mysqld --initialize(產生隨機密碼,自己保存隨機密碼後自行修改)
C:\>bin\mysqld --initialize-insecure(不產生密碼)
第一種參考:http://www.cnblogs.com/leeyes999/p/5476504.html
本文主要介紹第二種
2.3.5.5 Starting the Server for the First Time
mysqld --console可以打印相關控制台日志
啟動數據庫輸入 net start mysql
連接數據庫:
if you used --initialize-insecure
to initialize the data directory, connect to the server as root
without a password:
mysql -u root --skip-password
連上後修改密碼:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password(自定義)'
;
2.3.5.6 Starting MySQL from the Windows Command Line
2.3.5.7 Customizing the PATH for MySQL Tools
2.3.5.8 Starting MySQL as a Windows Service
2.3.5.9 Testing The MySQL Installation