MySQL mysqld:无法将目录更改为数据。服务器未启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33752407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:24:39  来源:igfitidea点击:

mysqld: Can't change dir to data. Server doesn't start

mysql

提问by Feeco

I installed a MySQL server with installer and it started. After reboot I tried to start it again and get the error:

我用安装程序安装了一个 MySQL 服务器,它启动了。重新启动后,我尝试再次启动它并得到错误:

D:\Program Files\MySQL\MySQL Server 5.7\bin>mysqld -u root -p
mysqld: Can't change dir to 'D:\Program Files\MySQL\MySQL Server 5.7\data\'     (Errcode: 2 - No such file or directory)
2015-11-17T08:30:18.822962Z 0 [Warning] TIMESTAMP with implicit DEFAULT     value is deprecated. Please use --explicit_defaults_for_timestamp server option     (see documentation for more details).
2015-11-17T08:30:18.822962Z 0 [Warning] Insecure configuration for --secure-    file    -priv: Current value does not restrict location of generated files.     Consider setting it to a valid, non-empty path.
2015-11-17T08:30:18.822962Z 0 [Note] mysqld (mysqld 5.7.9) starting as     process 1108 ...
2015-11-17T08:30:18.838586Z 0 [Warning] Can't create test file D:\Program     Files\MySQL\MySQL Server 5.7\data\DESKTOP-RNBR3E8.lower-test
2015-11-17T08:30:18.838586Z 0 [Warning] Can't create test file D:\Program     Files\MySQL\MySQL Server 5.7\data\DESKTOP-RNBR3E8.lower-test
2015-11-17T08:30:18.838586Z 0 [ERROR] failed to set datadir to D:\Program     Files\MySQL\MySQL Server 5.7\data\
2015-11-17T08:30:18.838586Z 0 [ERROR] Aborting


2015-11-17T08:30:18.838586Z 0 [Note] Binlog end
2015-11-17T08:30:18.838586Z 0 [Note] mysqld: Shutdown complete

I tried to reinstall MySQL.
UPDATE:
When I run mysqld -u root -pas administrator, nothing happens.

我尝试重新安装 MySQL。
更新:
当我mysqld -u root -p以管理员身份运行时,没有任何反应。

采纳答案by AaronDanielson

Since you used the Windows installer, everything is set up for you to run MySQL 5.7 as a Windows service, which is a great option in most cases.

由于您使用了 Windows 安装程序,因此所有设置都可以让您将 MySQL 5.7 作为 Windows 服务运行,这在大多数情况下是一个不错的选择。

Instead of running mysqld.exefrom the command line,

而不是mysqld.exe从命令行运行,

  1. Win + R
  2. Run services.msc
  3. Right-click on MySQL57
  4. Start the service.
  1. Win + R
  2. services.msc
  3. 右键单击 MySQL57
  4. 启动服务。

回答by keerthiprasath

I have met same problem. In my case I had no ..\datadir in my C:\mysql\so I just executed mysqld --initializecommand from c:\mysql\bin\directory and I got the data directory in c:\mysql\data. Afterwards I could use mysqld.exe --consolecommand to test the server startup.

我遇到了同样的问题。就我而言,我的..\data目录中没有 目录,C:\mysql\所以我只是mysqld --initializec:\mysql\bin\目录中执行命令,然后在c:\mysql\data. 之后我可以使用mysqld.exe --console命令来测试服务器启动。

回答by Hanshan

In my case, I had installed the data directory to a different location. So the data directory really wasn't in the default location. Therefore, when I ran the mysqldcommand from the command prompt, I had to specify the data directory manually:

就我而言,我已将数据目录安装到不同的位置。所以数据目录确实不在默认位置。因此,当我mysqld从命令提示符运行命令时,我必须手动指定数据目录:

mysqld --datadir=D:/MySQLData/Data

mysqld --datadir=D:/MySQLData/Data

Here's the documentation for mysqld command-line arguments.

这是 mysqld 命令行参数的文档。

回答by Keith Ballantyne

What I did (Windows 10) for a new installation:

我为新安装所做的(Windows 10):

  1. Start cmd in admin mode (run as administrator by hitting windows key, typing cmd, right clicking on it and selecting "Run as Administrator"

  2. Change into "MySQL Server X.Y" directory (for me the full path is C:\Program Files\MySQL\MySQL Server 5.7")

  3. using notepad create a my.ini with a mysqld section that points at your data directory

    [mysqld]
    datadir="X:\Your Directory Path and Name"
    
  4. created the directory identified in my.ini above.

  5. change into bin Directory under server directory and execute: mysqld --initialize

  6. Once complete, started the service and it came up fine.

  1. 以管理员模式启动 cmd(以管理员身份运行,按 Windows 键,键入 cmd,右键单击它并选择“以管理员身份运行”

  2. 更改为“MySQL Server XY”目录(对我而言,完整路径为 C:\Program Files\MySQL\MySQL Server 5.7”)

  3. 使用记事本创建一个带有 mysqld 部分的 my.ini,该部分指向您的数据目录

    [mysqld]
    datadir="X:\Your Directory Path and Name"
    
  4. 创建了上面 my.ini 中标识的目录。

  5. 切换到服务器目录下的bin目录,执行: mysqld --initialize

  6. 完成后,启动服务,结果很好。

回答by Stephane Paquet

  1. Check that the director exists.
  2. If it exists make sure mysql has access rights on it (read/write). Can be a good idea to run MySQL as a system process, but not mandatory.
  1. 检查导演是否存在。
  2. 如果它存在,请确保 mysql 对其具有访问权限(读/写)。将 MySQL 作为系统进程运行是一个好主意,但不是强制性的。

If this is stil not working try having the following notation with double slashes: C:\WebSerer\MySQL\data or C:/WebServer/MySQL/data

如果这仍然不起作用,请尝试使用以下带双斜杠的符号:C:\WebSerer\MySQL\data 或 C:/WebServer/MySQL/data

回答by Nizar

First run

第一次运行

mysqld -u root --initialize-insecure 

It will create data folder with root as user without password. Then run

它将以 root 用户身份创建数据文件夹,无需密码。然后运行

mysqld.exe -u root --console

回答by mariofertc

In mysql 8.0.13 zip package initializing.

在 mysql 8.0.13 zip 包初始化中。

  1. Verify that data folder is empty.
  2. Under the mysql bin path run

    mysqld.exe --initialize-insecure

  3. Add to my.ini native mysql

    [mysqld]

    default_authentication_plugin=mysql_native_password

  1. 验证数据文件夹是否为空。
  2. 在mysql bin路径下运行

    mysqld.exe --initialize-insecure

  3. 添加到 my.ini 原生 mysql

    [mysqld]

    default_authentication_plugin=mysql_native_password

回答by DRoberts

mariofertc completely solved this for me here are his steps:

mariofertc 为我完全解决了这个问题,这是他的步骤:

  1. Verify mysql's data directory is empty (before you delete it though, save the err file for your records).

  2. Under the mysql bin path run: mysqld.exe --initialize-insecure

  3. add to my.ini (mysql's configuration file) the following: [mysqld] default_authentication_plugin=mysql_native_password

  1. 验证 mysql 的数据目录是否为空(在删除它之前,请保存 err 文件以供记录)。

  2. 在mysql bin路径下运行:mysqld.exe --initialize-insecure

  3. 在 my.ini(mysql 的配置文件)中添加以下内容: [mysqld] default_authentication_plugin=mysql_native_password

Then check services (via task manager) to make sure MySql is running, if not - right click MySql and start it.

然后检查服务(通过任务管理器)以确保 MySql 正在运行,如果没有 - 右键单击​​ MySql 并启动它。

I'll also note, if you don't have your mysql configuration file in the mysql bin and can't find it via the windows search, you will want to look for it in C:\Program Data\Mysql\ Note that it might be a different name other than my.ini, like a template, as Heesu mentions here: Can't find my.ini (mysql 5.7)Just find the template that matches the version of your mysql via the command mysql --version

我还要注意,如果你在 mysql bin 中没有你的 mysql 配置文件并且无法通过 windows 搜索找到它,你将要在 C:\Program Data\Mysql\ 中寻找它,注意它可能是除 my.ini 之外的其他名称,例如模板,正如 Heesu 在此处提到的:无法找到 my.ini (mysql 5.7)只需通过命令 mysql --version 找到与您的 mysql 版本匹配的模板

回答by Suleiman Umar

When I encountered this same error, I noticed MySQL Configuration file in "C:\Program Files\MySQL\MySQL Server X.Y\" has changed to my-default.ini

当我遇到同样的错误时,我注意到“C:\Program Files\MySQL\MySQL Server XY\”中的 MySQL 配置文件已更改为 my-default.ini

I solved it by

我解决了

  1. Copy my.ini from "C:\ProgramData\MySQL\MySQL Server X.Y\my.ini"
  2. Paste it in "C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
  3. Restart MySQL Server from services.msc
  1. 从“C:\ProgramData\MySQL\MySQL Server XY\my.ini”复制 my.ini
  2. 将其粘贴到“C:\Program Files\MySQL\MySQL Server XY\my.ini”中
  3. 从 services.msc 重新启动 MySQL 服务器

In the .ini file, their is part that reads:

在 .ini 文件中,它们的部分内容如下:

# On Windows you should keep this file in the installation directory 
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option 
# "--defaults-file". 

回答by Tom DE RUDDER

remove all files in "{path-to-mysql}\data" directory and run:

删除“{path-to-mysql}\data”目录中的所有文件并运行:

mysqld --initialize-insecure --basedir={path-to-mysql}\mysql --datadir={path-to-mysql}\data --console