Windows10安裝MySQL5.7.18解壓縮版

Windows10安裝MySQL5.7.18解壓縮版

由於是邊安裝邊寫,並且MySQL5.7版本及之後安裝都挺蛋疼的,因此可能有不少玄學錯誤致使安裝沒法成功。總之請多指教。html

安裝環境以及軟件版本

Windows:Windows10 x64 家庭中文版mysql

MySQL:Microsoft Windows x86,64-bit zip archiveweb

安裝過程

1.下載安裝文件

簡單來講就是:登錄官網(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

以後下載過程就會開始。數據庫

2.開始安裝

按照官方的文檔: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

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:安全

  1. 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

  2. Create an option file工具

  3. Choose a MySQL server type

  4. Initialize MySQL

  5. Start the MySQL server

  6. Secure the default user accounts

This process is described in the sections that follow.

 可知步驟大概是:

  1. 解壓文件到安裝目錄
  2. 建立配置文件
  3. 選擇安裝類型
  4. 初始化MySQL
  5. 啓動MySQL服務
  6. 確保用戶帳戶安全

這幾個步驟。看起來挺簡單的,但考慮到MySQL的安裝有多坑,我仍是挺慌的。

那麼,我也按文檔一步步安裝吧。

1.建立一個安裝目錄並將下載好的安裝文件解壓到目錄中

如圖,而後是解壓。

對了,文檔上有幾個要點要注意下:

2.3.5.1 Extracting the Install Archive

To install MySQL manually, do the following:

  1. If you are upgrading from a previous version please refer to Section 2.3.8, 「Upgrading MySQL on Windows」, before beginning the upgrade process.

  2. Make sure that you are logged in as a user with administrator privileges.

  3. Choose an installation location. Traditionally, the MySQL server is installed in C:\mysql. The MySQL Installation Wizard installs MySQL under C:\Program Files\MySQL. If you do not install MySQL at C:\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」.

    Note

    The MySQL Installer installs MySQL under C:\Program Files\MySQL.

  4. 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. 有些壓縮軟件會在解壓縮時把結果放入一個目錄中方便管理,若是發生這種狀況,請將解壓縮的內容移動到上一級文件夾中

關於第1條,我也不知道要怎麼確認,走一步算一步吧。而第2條,如今的壓縮工具都是這樣的啊。總之,多謝相告。

如圖,解壓的結果就是這樣了。考慮下剛纔文檔裏說的,姑且把裏面的內容移到上一層目錄吧,如圖:

那麼開始下一步吧。

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 like C:\WINDOWS. You can determine its exact location from the value of the WINDIR 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 the my.cnf file. However, to avoid confusion, it is best if you use only one file. If your PC uses a boot loader where C: is not the boot drive, your only option is to use the my.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.cnf Global options
%WINDIR%\my.ini%WINDIR%\my.cnf Global options
C:\my.iniC:\my.cnf Global options
BASEDIR\my.iniBASEDIR\my.cnf Global options
defaults-extra-file The file specified with --defaults-extra-file, if any
%APPDATA%\MySQL\.mylogin.cnf Login 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 to C:\ProgramData on Microsoft Windows Vista and greater, and C:\Documents and Settings\All Users\Application Data on older versions of Microsoft Windows.

%WINDIR% represents the location of your Windows directory. This is commonly C:\WINDOWS. Use the following command to determine its exact location from the value of the WINDIR 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 the APPDATA environment variable:

C:\> 
echo %APPDATA%

BASEDIR represents the MySQL base installation directory. When MySQL 5.7 has been installed using MySQL Installer, this is typically C:\PROGRAMDIR\MySQL\MySQL 5.7 Server where PROGRAMDIR represents the programs directory (usually Program 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

只是啓動的話這樣的內容應該是足夠的。

3.選擇MySQL服務類型

其實我也不懂這個MySQL服務類型指的是什麼。存粹是根據 2.3.5.3 Selecting a MySQL Server Type 文檔標題直譯的。總之一步步來吧。

看過文檔,貌似這一步只是科普,什麼都不用作。那麼咱們一頭霧水開始下一步吧。

4.初始化數據庫目錄文件

這一步十分重要。相信有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:

根據文檔所述,在5.7.7之前的Windows發行版都包含了已經預初始化的數據庫文件的,可是以後的版本都要用戶手動初始化。真煩。

根據文檔2.10.1.1 Initializing the Data Directory Manually Using mysqld上所述,結合這次安裝具體狀況來看,擬定步驟以下:

  1. 以管理員權限啓動cmd
  2. 進入安裝目錄
  3. 執行初始化命令:mysqld.exe --defaults-file=D:\webserver\mysql-5.7.18\my.ini --initialize-insecure
    • 由於發現了--defaults-file 選項,爲了保險起見,仍是用它指定了配置文件的位置
    • 使用 --initialize-insecure 而不是--initialize 是由於能夠生成一個無密碼root帳號

而後等就好了...應該沒問題吧。過程如圖:

哦,對了。有個細節忘記交代。那就是要先創建一個數據庫文件夾,而後在配置文件中指明。

我這裏就建立在了安裝目錄下,如圖:

原本是個空目錄,在執行了初始化以後,裏面有了文件,如圖:

這一步應該算是成功了。

5.首次啓動服務

根據文檔,說是執行 mysqld.exe --console 就好了。固然是要在安裝目錄下。如圖:

按文檔上來講應該是這樣:

To start the server, enter this command:

C:\> 
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld" --console

For 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: Started

When 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: 3306

The 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.

然而,我這裏是這樣的:

不知道這是...但姑且樂觀得認爲成功了吧。下一步,下一步。

6.經過命令行啓動MySQL

經過參考文檔,步驟以下:

  1. 打開cmd
  2. 進入安裝目錄下的bin目錄
  3. 輸入指令mysql.exe -u root

由於初始化參數的關係,root帳戶沒有密碼。過程如圖:

到這一步能夠說是ok了。

至於第第5步的玄學報錯,實在懶得去查文檔了,若是哪位讀者知道的話還望不吝賜教,不勝感激。

總結

1.啓動和關閉服務的方法

啓動是在安裝目錄的bin目錄下執行 mysqld.exe --defaults-file=D:\webserver\mysql-5.7.18\my.ini ,關閉的話須要執行 mysqladmin -u root shutdown 。

2.配置文件

個人配置文件只有4行,確定是不夠的,但只是簡單使用的話也沒問題。總之不在這裏擴展了,之後在說吧。

相關文章
相關標籤/搜索