首次安装和运行 MySQL 时,您可能会遇到某些阻止 MySQL 服务器启动的错误。本部分可帮助您诊断并纠正其中一些错误。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 服务器使用错误日志来记录与阻止服务器启动的错误相关的信息。错误日志位于 my.ini 文件中指定的数据目录。默认数据目录位置为 C:\Program Files\MySQL\MySQL
Server 8.4\data,或 Windows 7 和 Windows Server 2008 上的 C:\ProgramData\Mysql。默认情况下,C:\ProgramData 目录是隐藏的。您需要更改文件夹选项才能查看目录和内容。有关错误日志的详细信息并了解其内容,请参阅第 7.4.2 节“错误日志”。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. The error log is located
in the data directory
specified in your my.ini file. The default
data directory location is C:\Program Files\MySQL\MySQL
Server 8.4\data, or
C:\ProgramData\Mysql on Windows 7 and Windows
Server 2008. The C:\ProgramData directory is
hidden by default. 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 7.4.2, “The Error Log”.
For information regarding possible errors, also consult the
console messages displayed when the MySQL service is starting. Use
the SC 启动mysqld_service_name或者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. See
Section 2.3.3.8, “Starting MySQL as a Windows Service”.For information regarding possible errors, also consult the
console messages displayed when the MySQL service is starting. Use
the SC START
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. See
Section 2.3.3.8, “Starting MySQL as a Windows Service”.
以下示例显示了在安装 MySQL 和首次启动服务器时可能遇到的其他常见错误消息:The following examples show other common error messages you might encounter when installing MySQL and starting the server for the first time:
如果 MySQL 服务器找不到
mysql权限数据库或其他关键文件时,它会显示以下消息:If the MySQL server cannot find themysqlprivileges 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
当 MySQL 基本目录或数据目录安装在默认位置以外的位置(分别为
C:\Program Files\MySQL\MySQL Server 8.4和C:\Program Files\MySQL\MySQL Server 8.4\data)时,通常会出现这些消息。These messages often occur when the MySQL base or data directories are installed in different locations than the default locations (C:\Program Files\MySQL\MySQL Server 8.4andC:\Program Files\MySQL\MySQL Server 8.4\data, respectively).当 MySQL 升级并安装到新位置,但配置文件未安装时,可能会出现这种情况。已更新以反映新位置。此外,新旧配置文件可能会发生冲突。升级 MySQL 时请务必删除或重命名任何旧配置文件。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 安装到
C:\Program Files\MySQL\MySQL Server 8.4以外的目录,请确保 MySQL 服务器通过使用配置 (my.ini) 文件了解这一点。将my.ini文件放入 Windows 目录中,通常为C:\WINDOWS。要根据WINDIR环境变量的值确定其确切位置,请从命令提示符发出以下命令:If you have installed MySQL to a directory other thanC:\Program Files\MySQL\MySQL Server 8.4, ensure that the MySQL server is aware of this through the use of a configuration (my.ini) file. Put themy.inifile in your Windows directory, typicallyC:\WINDOWS. To determine its exact location from the value of theWINDIRenvironment variable, issue the following command from the command prompt:C:\>
echo %WINDIR%您可以使用任何文本编辑器(例如记事本)创建或修改选项文件。例如,如果 MySQL 安装在
E:\mysql中,数据目录为D:\MySQLdata,则可以创建选项文件并设置[mysqld]部分来指定basedir和datadir选项的值:You can create or modify an option file with any text editor, such as Notepad. For example, if MySQL is installed inE:\mysqland the data directory isD:\MySQLdata, you can create the option file and set up a[mysqld]section to specify values for thebasediranddatadiroptions:[mysqld] # set basedir to your installation path basedir=E:/mysql # set datadir to the location of your data directory datadir=D:/MySQLdata
Microsoft Windows 路径名在选项文件中使用 (forward) 指定斜杠而不是反斜杠。如果确实使用反斜杠,请将其加倍:Microsoft Windows path names are specified in option files using (forward) slashes rather than backslashes. If you do use backslashes, double them:
[mysqld] # set basedir to your installation path basedir=C:\\Program Files\\MySQL\\MySQL Server 8.4 # set datadir to the location of your data directory datadir=D:\\MySQLdata
第 6.2.2.2 节“使用选项文件” 中给出了在选项文件值中使用反斜杠的规则。The rules for use of backslash in option file values are given in Section 6.2.2.2, “Using Option Files”.
如果更改 MySQL 配置文件中的
datadir值,则必须将重新启动 MySQL 服务器之前,请先检查现有 MySQL 数据目录的内容。If you change thedatadirvalue in your MySQL configuration file, you must move the contents of the existing MySQL data directory before restarting the MySQL server.请参阅第 2.3.3.2 节 “创建选项文件”。See Section 2.3.3.2, “Creating an Option File”.
如果在未先停止和删除现有 MySQL 服务的情况下重新安装或升级 MySQL,然后使用 MySQL Configurator 配置 MySQL,则可能会出现以下情况:看到以下错误:If you reinstall or upgrade MySQL without first stopping and removing the existing MySQL service, and then configure MySQL using MySQL Configurator, you might see this error:
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.
此问题的一种解决方案是在使用配置向导时选择
mysql以外的服务名称。这使得新服务能够正确安装,但过时的服务仍保留在原处。虽然这无害,但最好删除不再使用的旧服务。One solution to this problem is to choose a service name other thanmysqlwhen using the configuration wizard. 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.要永久删除旧的
mysql服务,请以具有管理权限的用户身份在命令行上执行以下命令:To permanently remove the oldmysqlservice, execute the following command as a user with administrative privileges, on the command line:C:\>
SC DELETE mysql[SC] DeleteService SUCCESS如果
SC此实用程序不适用于您的 Windows 版本,请从delsrv下载该实用程序http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/delsrv-o.asp并使用delsrv mysql语法。If theSCutility is not available for your version of Windows, download thedelsrvutility from http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/delsrv-o.asp and use thedelsrv mysqlsyntax.