8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 2 安装 MySQL / 2.3 在 Microsoft Windows 上安装 MySQL / 2.3.4 Microsoft Windows MySQL 服务器安装故障排除
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

2.3.4 Microsoft Windows MySQL 服务器安装故障排除2.3.4 Troubleshooting a Microsoft Windows MySQL Server Installation

首次安装和运行 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 the 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
    

    当 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.4 and C:\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 than C:\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 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:

    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 in 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:

    [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 the datadir value 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 than mysql when 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 old mysql service, 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 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.