Windows10安装MySQL5.7.18解压缩版

2018-06-17 23:37:40来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

Windows10安装MySQL5.7.18解压缩版

因为是边安装边写,而且MySQL5.7版本及以后安装都挺蛋疼的,所以可能有很多玄学错误导致安装无法成功。总之请多指教。

安装环境以及软件版本

Windows:Windows10 x64 家庭中文版

MySQL:Microsoft Windows x86,64-bit zip archive

安装过程

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.

之后下载过程就会开始。

2.开始安装

按照官方的文档:https://dev.mysql.com/doc/refman/5.7/en/windows-install-archive.html

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:

  1. Extract the main archive to the desired install directory

    Optional: also extract the debug-test archive if you plan to execute the MySQL benchmark and test suite

  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 NamePurpose
%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:

  • 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上所述,结合此次安装具体情况来看,拟定步骤如下:

  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行,肯定是不够的,但只是简单使用的话也没问题。总之不在这里扩展了,以后在说吧。

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:MySQL数据库

下一篇:解决小黑框无法插入中文数据和乱码的情况