由於是邊安裝邊寫,並且MySQL5.7版本及之後安裝都挺蛋疼的,因此可能有不少玄學錯誤致使安裝沒法成功。總之請多指教。html
Windows:Windows10 x64 家庭中文版mysql
MySQL:Microsoft Windows x86,64-bit zip archiveweb
簡單來講就是:登錄官網(https://www.mysql.com/)=>Downloads=>Community=>MySQL Community Server=>Microsoft Windows & Windows(x86,64-bit)=>ZIP Archive & Download=>No thanks, just start my download.sql
以後下載過程就會開始。數據庫
按照官方的文檔:https://dev.mysql.com/doc/refman/5.7/en/windows-install-archive.htmlwindows
2.3.5 Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
- 2.3.5.1 Extracting the Install Archive
- 2.3.5.2 Creating an Option File
- 2.3.5.3 Selecting a MySQL Server Type
- 2.3.5.4 Initializing the Data Directory
- 2.3.5.5 Starting the Server for the First Time
- 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
Users who are installing from the
noinstall
package can use the instructions in this section to manually install MySQL. The process for installing MySQL from a Zip archive is as follows:安全
Extract the main archive to the desired install directoryapp
Optional: also extract the debug-test archive if you plan to execute the MySQL benchmark and test suitesocket
Create an option file工具
Choose a MySQL server type
Initialize MySQL
Start the MySQL server
Secure the default user accounts
This process is described in the sections that follow.
可知步驟大概是:
這幾個步驟。看起來挺簡單的,但考慮到MySQL的安裝有多坑,我仍是挺慌的。
那麼,我也按文檔一步步安裝吧。
如圖,而後是解壓。
對了,文檔上有幾個要點要注意下:
2.3.5.1 Extracting the Install Archive
To install MySQL manually, do the following:
If you are upgrading from a previous version please refer to Section 2.3.8, 「Upgrading MySQL on Windows」, before beginning the upgrade process.
Make sure that you are logged in as a user with administrator privileges.
Choose an installation location. Traditionally, the MySQL server is installed in
C:\mysql
. The MySQL Installation Wizard installs MySQL underC:\Program Files\MySQL
. If you do not install MySQL atC:\mysql
, you must specify the path to the install directory during startup or in an option file. See Section 2.3.5.2, 「Creating an Option File」.NoteThe MySQL Installer installs MySQL under
C:\Program Files\MySQL
.Extract the install archive to the chosen installation location using your preferred Zip archive tool. Some tools may extract the archive to a folder within your chosen installation location. If this occurs, you can move the contents of the subfolder into the chosen installation location.
注意第2條和第4條,有兩點須要注意:
關於第1條,我也不知道要怎麼確認,走一步算一步吧。而第2條,如今的壓縮工具都是這樣的啊。總之,多謝相告。
如圖,解壓的結果就是這樣了。考慮下剛纔文檔裏說的,姑且把裏面的內容移到上一層目錄吧,如圖:
那麼開始下一步吧。
根據文檔內容:
When the MySQL server starts on Windows, it looks for option files in several locations, such as the Windows directory,
C:\
, and the MySQL installation directory (for the full list of locations, see Section 5.2.6, 「Using Option Files」). The Windows directory typically is named something likeC:\WINDOWS
. You can determine its exact location from the value of theWINDIR
environment variable using the following command:C:\> echo %WINDIR%MySQL looks for options in each location first in the
my.ini
file, and then in themy.cnf
file. However, to avoid confusion, it is best if you use only one file. If your PC uses a boot loader whereC:
is not the boot drive, your only option is to use themy.ini
file. Whichever option file you use, it must be a plain text file.
貌似,配置文件my.ini必須放在系統目錄中。若是不知道這個目錄位置,能夠用 echo %WINDIR% 來獲取。如圖:
能夠看到,C:\Windows正是這個Windows Directory。可是,這個目錄裏面的文件多且雜,並且大多對於系統很重要,且這個文件是有訪問控制的,我擔憂程序會由於權限的緣由啓動失敗。考慮這些緣由,仍是不要把配置文件放入系統目錄爲好。
那麼,能夠放在其它路徑麼?讓我翻一下文檔。
On Windows, MySQL programs read startup options from the files shown in the following table, in the specified order (top files are read first, files read later take precedence).
Table 5.1 Option Files Read on Windows Systems
File Name Purpose ,
%PROGRAMDATA%
\MySQL\MySQL Server 5.7\my.ini
%PROGRAMDATA%
\MySQL\MySQL Server 5.7\my.cnfGlobal options ,
%WINDIR%
\my.ini
%WINDIR%
\my.cnfGlobal options C:\my.ini
,C:\my.cnf
Global options ,
BASEDIR
\my.ini
BASEDIR
\my.cnfGlobal options defaults-extra-file
The file specified with --defaults-extra-file
, if any
%APPDATA%
\MySQL\.mylogin.cnfLogin path options (clients only)
In the preceding table,
%PROGRAMDATA%
represents the file system directory that contains application data for all users on the host. This path defaults toC:\ProgramData
on Microsoft Windows Vista and greater, andC:\Documents and Settings\All Users\Application Data
on older versions of Microsoft Windows.
%WINDIR%
represents the location of your Windows directory. This is commonlyC:\WINDOWS
. Use the following command to determine its exact location from the value of theWINDIR
environment variable:C:\> echo %WINDIR%
%APPDATA%
represents the value of the Windows application data directory. Use the following command to determine its exact location from the value of theAPPDATA
environment variable:C:\> echo %APPDATA%
BASEDIR
represents the MySQL base installation directory. When MySQL 5.7 has been installed using MySQL Installer, this is typicallyC:\
wherePROGRAMDIR
\MySQL\MySQL 5.7 ServerPROGRAMDIR
represents the programs directory (usuallyProgram Files
on English-language versions of Windows), See Section 2.3.3, 「MySQL Installer for Windows」.
在文檔5.2.6 Using Option Files中,有配置文件的讀取順序。看不懂第一條是什麼鬼,不過能夠看出第4條是指安裝目錄。雖然優先級不高,可是應該其它目錄沒有同名的文件就能生效。
那麼在安裝目錄下創建配置文件:
注意文件的編碼格式最好是utf-8無BOM格式。內容以下:
[mysqld] basedir=D:\\webserver\\mysql-5.7.18 datadir=D:\\webserver\\mysql-5.7.18\\data port=3306
只是啓動的話這樣的內容應該是足夠的。
其實我也不懂這個MySQL服務類型指的是什麼。存粹是根據 2.3.5.3 Selecting a MySQL Server Type 文檔標題直譯的。總之一步步來吧。
看過文檔,貌似這一步只是科普,什麼都不用作。那麼咱們一頭霧水開始下一步吧。
這一步十分重要。相信有Linux或Unix編譯安裝MySQL經歷的都應該有所瞭解。總的來講,這一步用來生成數據庫數據文件。
2.3.5.4 Initializing the Data Directory
If you installed MySQL using the
Noinstall
package, you may need to initialize the data directory:
Windows distributions prior to MySQL 5.7.7 include a data directory with a set of preinitialized accounts in the
mysql
database.As of 5.7.7, Windows installation operations performed using the
Noinstall
package do not include a data directory. To initialize the data directory, use the instructions at Section 2.10.1.1, 「Initializing the Data Directory Manually Using mysqld」.
根據文檔所述,在5.7.7之前的Windows發行版都包含了已經預初始化的數據庫文件的,可是以後的版本都要用戶手動初始化。真煩。
根據文檔2.10.1.1 Initializing the Data Directory Manually Using mysqld上所述,結合這次安裝具體狀況來看,擬定步驟以下:
而後等就好了...應該沒問題吧。過程如圖:
哦,對了。有個細節忘記交代。那就是要先創建一個數據庫文件夾,而後在配置文件中指明。
我這裏就建立在了安裝目錄下,如圖:
原本是個空目錄,在執行了初始化以後,裏面有了文件,如圖:
這一步應該算是成功了。
根據文檔,說是執行 mysqld.exe --console 就好了。固然是要在安裝目錄下。如圖:
按文檔上來講應該是這樣:
To start the server, enter this command:
C:\> "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld" --consoleFor a server that includes
InnoDB
support, you should see the messages similar to those following as it starts (the path names and sizes may differ):InnoDB: The first specified datafile c:\ibdata\ibdata1 did not exist: InnoDB: a new database to be created! InnoDB: Setting file c:\ibdata\ibdata1 size to 209715200 InnoDB: Database physically writes the file full: wait... InnoDB: Log file c:\iblogs\ib_logfile0 did not exist: new to be created InnoDB: Setting log file c:\iblogs\ib_logfile0 size to 31457280 InnoDB: Log file c:\iblogs\ib_logfile1 did not exist: new to be created InnoDB: Setting log file c:\iblogs\ib_logfile1 size to 31457280 InnoDB: Log file c:\iblogs\ib_logfile2 did not exist: new to be created InnoDB: Setting log file c:\iblogs\ib_logfile2 size to 31457280 InnoDB: Doublewrite buffer not found: creating new InnoDB: Doublewrite buffer created InnoDB: creating foreign key constraint system tables InnoDB: foreign key constraint system tables created 011024 10:58:25 InnoDB: StartedWhen the server finishes its startup sequence, you should see something like this, which indicates that the server is ready to service client connections:
mysqld: ready for connections Version: '5.7.19' socket: '' port: 3306The server continues to write to the console any further diagnostic output it produces. You can open a new console window in which to run client programs.
然而,我這裏是這樣的:
不知道這是...但姑且樂觀得認爲成功了吧。下一步,下一步。
經過參考文檔,步驟以下:
由於初始化參數的關係,root帳戶沒有密碼。過程如圖:
到這一步能夠說是ok了。
至於第第5步的玄學報錯,實在懶得去查文檔了,若是哪位讀者知道的話還望不吝賜教,不勝感激。
啓動是在安裝目錄的bin目錄下執行 mysqld.exe --defaults-file=D:\webserver\mysql-5.7.18\my.ini ,關閉的話須要執行 mysqladmin -u root shutdown 。
個人配置文件只有4行,確定是不夠的,但只是簡單使用的話也沒問題。總之不在這裏擴展了,之後在說吧。