If you need to specify startup options when you run the server, you can indicate them on the command line or place them in an option file. 如果在运行服务器时需要指定启动选项,可以在命令行中指示它们,也可以将它们放在选项文件中。For options that are used every time the server starts, you may find it most convenient to use an option file to specify your MySQL configuration. This is particularly true under the following circumstances:对于每次服务器启动时使用的选项,您可能会发现使用选项文件来指定MySQL配置是最方便的。在以下情况下尤其如此:
The installation or data directory locations are different from the default locations (安装或数据目录的位置与默认位置不同(C:\Program Files\MySQL\MySQL Server 8.0
and C:\Program Files\MySQL\MySQL Server 8.0\data
).C:\Program Files\MySQL\MySQL Server 8.0
和C:\Program Files\MySQL\MMySQL Server 8.0\data
)。
You need to tune the server settings, such as memory, cache, or InnoDB configuration information.您需要调整服务器设置,例如内存、缓存或InnoDB
配置信息。
When the MySQL server starts on Windows, it looks for option files in several locations, such as the Windows directory, 当MySQL服务器在Windows上启动时,它会在多个位置查找选项文件,如Windows目录C:\
, and the MySQL installation directory (for the full list of locations, see Section 4.2.2.2, “Using Option Files”). C:\
和MySQL安装目录(有关位置的完整列表,请参阅第4.2.2.2节,“使用选项文件”)。The Windows directory typically is named something like Windows目录的名称通常类似于C:\WINDOWS
. C:\Windows
。You can determine its exact location from the value of the 可以使用以下命令根据WINDIR
environment variable using the following command:WINDIR
环境变量的值确定其确切位置:
C:\> echo %WINDIR%
MySQL looks for options in each location first in the MySQL首先在my.ini
file, and then in the my.cnf
file. my.ini
文件中的每个位置查找选项,然后在my.cnf
文件中查找选项。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. C:
不是引导驱动器的引导加载程序,那么您唯一的选择就是使用my.ini
文件。Whichever option file you use, it must be a plain text file.无论使用哪种选项文件,都必须是纯文本文件。
When using the MySQL Installer to install MySQL Server, it creates the 当使用MySQL安装程序安装MySQL Server时,它会在默认位置创建my.ini
at the default location, and the user executing MySQL Installer is granted full permissions to this new my.ini
file.my.ini
,并且执行MySQL安装程序的用户会被授予对这个新的my.ini
文件的完全权限。
In other words, be sure that the MySQL Server user has permission to read the 换句话说,请确保MySQL Server用户具有读取my.ini
file.my.ini
文件的权限。
You can also make use of the example option files included with your MySQL distribution; see Section 5.1.2, “Server Configuration Defaults”.您还可以使用MySQL发行版中包含的示例选项文件;请参阅第5.1.2节,“服务器配置默认值”。
An option file can be created and modified with any text editor, such as Notepad. 选项文件可以使用任何文本编辑器(如记事本)创建和修改。For example, if MySQL is installed in 例如,如果MySQL安装在E:\mysql
and the data directory is in E:\mydata\data
, you can create an option file containing a [mysqld]
section to specify values for the basedir
and datadir
options:E:\mysql
中,并且数据目录位于E:\mydata\data
中,则可以创建一个包含[mysqld]
部分的选项文件,以指定basedir
和datadir
选项的值:
[mysqld] # set basedir to your installation path basedir=E:/mysql # set datadir to the location of your data directory datadir=E:/mydata/data
Microsoft Windows path names are specified in option files using (forward) slashes rather than backslashes. If you do use backslashes, double them:Microsoft Windows路径名在选项文件中使用(正)斜杠而不是反斜杠指定。如果使用反斜杠,请将其加倍:
[mysqld] # set basedir to your installation path basedir=E:\\mysql # set datadir to the location of your data directory datadir=E:\\mydata\\data
The rules for use of backslash in option file values are given in Section 4.2.2.2, “Using Option Files”.选项文件值中反斜杠的使用规则见第4.2.2.2节,“使用选项文件”。
The ZIP archive does not include a ZIP存档不包括data
directory. data
目录。To initialize a MySQL installation by creating the data directory and populating the tables in the mysql system database, initialize MySQL using either 要通过创建数据目录并填充MySQL系统数据库中的表来初始化MySQL安装,请使用--initialize
or --initialize-insecure
. --initialize
或--initialize-insecure
初始化MySQL。For additional information, see Section 2.10.1, “Initializing the Data Directory”.有关更多信息,请参阅第2.10.1节,“初始化数据目录”。
If you would like to use a data directory in a different location, you should copy the entire contents of the 如果要在其他位置使用数据目录,则应将data
directory to the new location. data
目录的全部内容复制到新位置。For example, if you want to use 例如,如果要使用E:\mydata
as the data directory instead, you must do two things:E:\mydata
作为数据目录,则必须执行两件事:
Move the entire 将整个data
directory and all of its contents from the default location (for example C:\Program Files\MySQL\MySQL Server 8.0\data
) to E:\mydata
.data
目录及其所有内容从默认位置(例如C:\Program Files\MySQL\MySQL Server 8.0\data
)移动到E:\mydata
。
Use a 每次启动服务器时,使用--datadir
option to specify the new data directory location each time you start the server.--datadir
选项指定新的数据目录位置。