本文同步至 http://www.waylau.com/windows-install-mysql-noinstall-zip/html
在 Windows 環境下,最簡單的安裝 MySQL 方式天然是使用 MySQL Installer 進行「傻瓜」式點下一步安裝便可,能夠參見mysql-5.6.13在windows平臺下的安裝、使用(圖解)。本文介紹了另一種使用 noinstall Zip 文件(免安裝版)安裝 MySQL。mysql
<!-- more -->sql
地址: http://dev.mysql.com/downloads/mysql/shell
本例使用 MySQL 版本爲:Windows (x86, 64-bit), ZIP Archive 5.7.10 (mysql-5.7.10-winx64.zip)windows
本例使用的操做系統爲:Win7 Sp1 x64服務器
C:\mysql
。 MySQL 的安裝嚮導(MySQL Installer)安裝 MySQL 在C:\Program Files\MySQL
。若是您沒有在 C:\mysql
安裝 MySQL,你必須在啓動或者在 option file 文件中指定的安裝目錄路徑。本例安裝在C:\Program Files\MySQL
目錄。配置文件是用於設置 MySQL 的配置,解壓包下有一個 my-default.ini 文件,就是模版。複製該模版從命名爲 my.ini,則 MySQL 就會從 my.ini 裏讀取配置。dom
my.ini 放在 C:\Windows
目錄。socket
本例安裝目錄和數據設置在 (C:\Program Files\MySQL\mysql-5.7.10-winx64
和 D:\mysqlData\data
),配置以下:ide
[mysqld] # set basedir to your installation path basedir = C:/Program Files/MySQL/mysql-5.7.10-winx64 # set datadir to the location of your data directory datadir = D:/mysqlData/data
MySQL 5.7.6 以後,noinstall 安裝包並無提供 data 目錄,因此要初始化一個 data 目錄工具
爲了方便使用 MySQL 工具,添加 MySQL bin 目錄添加到 PATH 是個不錯的選擇。
本例將 C:\Program Files\MySQL\mysql-5.7.10-winx64\bin
添加到 PATH,以下:
使用命令行
mysqld --defaults-file=C:\Windows\my.ini --initialize --console
其中 --defaults-file
指向了咱們以前建立的 my.ini 文件。
控制檯輸出以下:
C:\Users\Administrator>mysqld --defaults-file=C:\Windows\my.ini --initialize --c onsole 2016-01-03T04:38:27.634571Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc umentation for more details). 2016-01-03T04:38:27.634571Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'E RROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2016-01-03T04:38:27.634571Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not s et. 2016-01-03T04:38:29.196573Z 0 [Warning] InnoDB: New log files created, LSN=45790 2016-01-03T04:38:29.576574Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-01-03T04:38:29.696574Z 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: d657df18-b1d3-11e5-b812-00ac86a5db41. 2016-01-03T04:38:29.726574Z 0 [Warning] Gtid table is not ready to be used. Tabl e 'mysql.gtid_executed' cannot be opened. 2016-01-03T04:38:29.736574Z 1 [Note] A temporary password is generated for root@ localhost: m1>X:,<-2Gfl
若無異常,則會在 D:\mysqlData
下建立一個 data 文件夾。 其中,最後那個 m1>X:,<-2Gfl
就是 root 用戶的隨機生產的密碼
執行mysqld
就能啓動 MySQL server,或者執行 mysqld --console
能夠看到完整的啓動信息:
C:\Users\Administrator>mysqld --console 2016-01-03T03:39:47.313272Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc umentation for more details). 2016-01-03T03:39:47.313272Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'E RROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2016-01-03T03:39:47.313272Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not s et. 2016-01-03T03:39:47.313272Z 0 [Warning] Insecure configuration for --secure-file -priv: Current value does not restrict location of generated files. Consider set ting it to a valid, non-empty path. 2016-01-03T03:39:47.313272Z 0 [Note] mysqld (mysqld 5.7.10) starting as process 1420 ... 2016-01-03T03:39:47.313272Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows in terlocked functions 2016-01-03T03:39:47.313272Z 0 [Note] InnoDB: Uses event mutexes 2016-01-03T03:39:47.313272Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are u sed for memory barrier 2016-01-03T03:39:47.313272Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-01-03T03:39:47.313272Z 0 [Note] InnoDB: Number of pools: 1 2016-01-03T03:39:47.313272Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2016-01-03T03:39:47.328872Z 0 [Note] InnoDB: Initializing buffer pool, total siz e = 128M, instances = 1, chunk size = 128M 2016-01-03T03:39:47.344472Z 0 [Note] InnoDB: Completed initialization of buffer pool 2016-01-03T03:39:47.453673Z 0 [Note] InnoDB: Highest supported file format is Ba rracuda. 2016-01-03T03:39:47.469273Z 0 [Note] InnoDB: Log scan progressed past the checkp oint lsn 2492338 2016-01-03T03:39:47.469273Z 0 [Note] InnoDB: Doing recovery: scanned up to log s equence number 2492347 2016-01-03T03:39:47.469273Z 0 [Note] InnoDB: Doing recovery: scanned up to log s equence number 2492347 2016-01-03T03:39:47.469273Z 0 [Note] InnoDB: Database was not shutdown normally! 2016-01-03T03:39:47.469273Z 0 [Note] InnoDB: Starting crash recovery. 2016-01-03T03:39:48.186874Z 0 [Note] InnoDB: Removed temporary tablespace data f ile: "ibtmp1" 2016-01-03T03:39:48.186874Z 0 [Note] InnoDB: Creating shared tablespace for temp orary tables 2016-01-03T03:39:48.186874Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2016-01-03T03:39:48.389674Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2016-01-03T03:39:48.389674Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2016-01-03T03:39:48.389674Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2016-01-03T03:39:48.389674Z 0 [Note] InnoDB: Waiting for purge to start 2016-01-03T03:39:48.452074Z 0 [Note] InnoDB: 5.7.10 started; log sequence number 2492347 2016-01-03T03:39:48.452074Z 0 [Note] Plugin 'FEDERATED' is disabled. 2016-01-03T03:39:48.452074Z 0 [Note] InnoDB: Loading buffer pool(s) from D:\mysq lData\data\ib_buffer_pool 2016-01-03T03:39:48.452074Z 0 [Note] InnoDB: not started 2016-01-03T03:39:48.623675Z 0 [Warning] Failed to set up SSL because of the foll owing SSL library error: SSL context is not usable without certificate and priva te key 2016-01-03T03:39:48.623675Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2016-01-03T03:39:48.623675Z 0 [Note] IPv6 is available. 2016-01-03T03:39:48.623675Z 0 [Note] - '::' resolves to '::'; 2016-01-03T03:39:48.623675Z 0 [Note] Server socket created on IP: '::'. 2016-01-03T03:39:48.810875Z 0 [Note] Event Scheduler: Loaded 0 events 2016-01-03T03:39:48.810875Z 0 [Note] mysqld: ready for connections. Version: '5.7.10' socket: '' port: 3306 MySQL Community Server (GPL) 2016-01-03T03:39:48.904475Z 0 [Note] InnoDB: Buffer pool(s) load completed at 16 0103 11:39:48
關閉執行 mysqladmin -u root shutdown
做爲 Windows Service 能夠隨着操做系統自啓動。安裝前,先關閉 MySQL server,關閉執行 mysqladmin -u root shutdown
, 再執行 mysqld --install
便可。
若要卸載該服務器,執行mysqld --remove
將 MySQL server 做爲 Windows Service 安裝以後,能夠使用 NET 工具方便啓動、關閉 MySQL(指令不區分大小寫)。
啓動執行:
C:\Users\Administrator>NET START MySQL MySQL 服務正在啓動 . MySQL 服務已經啓動成功。
關閉執行:
C:\Users\Administrator>NET STOP MySQL MySQL 服務正在中止. MySQL 服務已成功中止。
在 MySQL server啓動後,用 root 用戶登錄
shell> mysql -u root -p Enter password: (enter the random root password here)
執行修改密碼的指令:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
執行mysqld --defaults-file=C:\Windows\my.ini --initialize
時,出現 下面稱爲:
C:\Users\Administrator>mysqld --defaults-file=C:\Windows\my.ini --initialize mysqld: Can't create directory 'D:\mysqlData\data\' (Errcode: 2 - No such file o r directory) 2016-01-01T15:08:10.531737Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc umentation for more details). 2016-01-01T15:08:10.531737Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'E RROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2016-01-01T15:08:10.531737Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not s et. 2016-01-01T15:08:10.534737Z 0 [ERROR] Aborting
解決方法:指定的目錄不存在,先建立D:\mysqlData
目錄,再執行上述命令