When installing and running MySQL for the first time, you may encounter certain errors that prevent the MySQL server from starting. This section helps you diagnose and correct some of these errors.第一次安装和运行MySQL时,可能会遇到某些错误,导致MySQL服务器无法启动。本节帮助您诊断和更正其中的一些错误。
Your first resource when troubleshooting server issues is the error log. 解决服务器问题时的第一个资源是错误日志。The MySQL server uses the error log to record information relevant to the error that prevents the server from starting. MySQL服务器使用错误日志来记录与阻止服务器启动的错误相关的信息。The error log is located in the data directory specified in your 错误日志位于my.ini
file. my.ini
文件中指定的数据目录中。The default data directory location is 默认的数据目录位置是C:\Program Files\MySQL\MySQL Server 8.0\data
, or C:\ProgramData\Mysql
on Windows 7 and Windows Server 2008. C:\Program Files\MySQL\MySQL Server 8.0\data
,或Windows 7和Windows Server 2008上的C:\ProgramData\MySQL
。The 默认情况下,C:\ProgramData
directory is hidden by default. C:\ProgramData
目录是隐藏的。You need to change your folder options to see the directory and contents. 您需要更改文件夹选项才能查看目录和内容。For more information on the error log and understanding the content, see Section 5.4.2, “The Error Log”.有关错误日志和理解内容的更多信息,请参阅第5.4.2节,“错误日志”。
For information regarding possible errors, also consult the console messages displayed when the MySQL service is starting. 有关可能的错误的信息,请参阅MySQL服务启动时显示的控制台消息。Use the SC START 在将mysqld作为服务安装后,从命令行使用mysqld_service_name
or NET START mysqld_service_name
command from the command line after installing mysqld as a service to see any error messages regarding the starting of the MySQL server as a service. SC START mysqld_service_name
或NET START mysqld_services_name
命令,查看有关将MySQL服务器作为服务启动的任何错误消息。See Section 2.3.4.8, “Starting MySQL as a Windows Service”.请参阅第2.3.4.8节,“将MySQL作为Windows服务启动”。
The following examples show other common error messages you might encounter when installing MySQL and starting the server for the first time:以下示例显示了在安装MySQL和首次启动服务器时可能遇到的其他常见错误消息:
If the MySQL server cannot find the 如果MySQL服务器找不到MySQL特权数据库或其他关键文件,则会显示以下消息:mysql
privileges database or other critical files, it displays these messages:
System error 1067 has occurred. Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
These messages often occur when the MySQL base or data directories are installed in different locations than the default locations (当MySQL基本目录或数据目录安装在与默认位置不同的位置(分别为C:\Program Files\MySQL\MySQL Server 8.0
and C:\Program Files\MySQL\MySQL Server 8.0\data
, respectively).C:\Program Files\MySQL\MySQL Server 8.0
和C:\Program Files\MySQL \MySQL Server8.0\data
)时,经常会出现这些消息。
This situation can occur when MySQL is upgraded and installed to a new location, but the configuration file is not updated to reflect the new location. In addition, old and new configuration files might conflict. Be sure to delete or rename any old configuration files when upgrading MySQL.当MySQL升级并安装到新位置,但配置文件没有更新以反映新位置时,可能会出现这种情况。此外,新旧配置文件可能会发生冲突。升级MySQL时,请确保删除或重命名任何旧的配置文件。
If you have installed MySQL to a directory other than 如果您已将MySQL安装到C:\Program Files\MySQL\MySQL Server 8.0
, ensure that the MySQL server is aware of this through the use of a configuration (my.ini
) file. C:\Program Files\MySQL\MySQL Server 8.0
以外的目录,请确保MySQL服务器通过使用配置(my.ini
)文件了解这一点。Put the 将my.ini
file in your Windows directory, typically C:\WINDOWS
. To determine its exact location from the value of the WINDIR
environment variable, issue the following command from the command prompt:my.ini
文件放在Windows目录中,通常是C:\Windows
。要根据WINDIR
环境变量的值确定其确切位置,请在命令提示符下发出以下命令:
C:\> echo %WINDIR%
You can create or modify an option file with any text editor, such as Notepad. 您可以使用任何文本编辑器(如记事本)创建或修改选项文件。For example, if MySQL is installed in 例如,如果MySQL安装在E:\mysql
and the data directory is D:\MySQLdata
, you can create the option file and set up a [mysqld]
section to specify values for the basedir
and datadir
options:E:\MySQL
中,数据目录为D:\MySQLdata
,则可以创建选项文件并设置[mysqld]
部分来指定basedir
和datadir
选项的值:
[mysqld] # set basedir to your installation path basedir=E:/mysql # set datadir to the location of your data directory datadir=D:/MySQLdata
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=C:\\Program Files\\MySQL\\MySQL Server 8.0 # set datadir to the location of your data directory datadir=D:\\MySQLdata
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节,“使用选项文件”。
If you change the 如果更改MySQL配置文件中的datadir值,则必须在重新启动MySQL服务器之前移动现有MySQL数据目录的内容。datadir
value in your MySQL configuration file, you must move the contents of the existing MySQL data directory before restarting the MySQL server.
See Section 2.3.4.2, “Creating an Option File”.请参阅第2.3.4.2节,“创建选项文件”。
If you reinstall or upgrade MySQL without first stopping and removing the existing MySQL service and install MySQL using the MySQL Installer, you might see this error:如果您在不首先停止和删除现有MySQL服务的情况下重新安装或升级MySQL,并使用MySQL安装程序安装MySQL,您可能会看到以下错误:
Error: Cannot create Windows service for MySql. Error: 0
This occurs when the Configuration Wizard tries to install the service and finds an existing service with the same name.当配置向导尝试安装服务并找到具有相同名称的现有服务时,就会发生这种情况。
One solution to this problem is to choose a service name other than 这个问题的一个解决方案是在使用配置向导时选择mysql
when using the configuration wizard. mysql
以外的服务名称。This enables the new service to be installed correctly, but leaves the outdated service in place. Although this is harmless, it is best to remove old services that are no longer in use.这使新服务能够正确安装,但保留了过时的服务。尽管这是无害的,但最好删除不再使用的旧服务。
To permanently remove the old 要永久删除旧的mysql
service, execute the following command as a user with administrative privileges, on the command line:mysql
服务,请以具有管理权限的用户身份在命令行上执行以下命令:
C:\> SC DELETE mysql
[SC] DeleteService SUCCESS
If the 如果SC
utility is not available for your version of Windows, download the delsrv
utility from http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/delsrv-o.asp and use the delsrv mysql
syntax.SC
实用程序不适用于您的Windows版本,请从下载delsrv
实用程序http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/delsrv-o.asp并使用delsrv -mysql
语法。