Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm following this tutorial here on creating a JDBC programming. I've followed the steps up to the console command to start the server:

// For Windows
cd {path-to-mysql-bin}   // Check your MySQL installed directory
mysqld --console

I get the following error message:

mysqld: Can't change dir to 'C:\Program Files\MySQL\MySQL Server 5.7\data\' (Errcode: 2 - No such file or directory)
2017-01-06T10:54:36.968210Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-01-06T10:54:36.968210Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2017-01-06T10:54:36.968210Z 0 [Note] mysqld (mysqld 5.7.17) starting as process 11248 ...
2017-01-06T10:54:36.974226Z 0 [Warning] Can't create test file C:\Program Files\MySQL\MySQL Server 5.7\data\DESKTOP-DEQ2IC2.lower-test
2017-01-06T10:54:36.975229Z 0 [Warning] Can't create test file C:\Program Files\MySQL\MySQL Server 5.7\data\DESKTOP-DEQ2IC2.lower-test
2017-01-06T10:54:36.975229Z 0 [ERROR] failed to set datadir to C:\Program Files\MySQL\MySQL Server 5.7\data\
2017-01-06T10:54:36.976231Z 0 [ERROR] Aborting
2017-01-06T10:54:36.977234Z 0 [Note] Binlog end
2017-01-06T10:54:36.978237Z 0 [Note] mysqld: Shutdown complete

I'm quite new to using MySql in this way but I can see that there is no data folder in the server directory and no my.ini file which I assumes holds the config information on where the data directory is. I've also insntalled MySql using the windows installer which I've read could be why there is no my.ini file and just a template my-default.ini file.

Does anyone know why this is happening?

You might want to do this from an administrator command prompt, see also stackoverflow.com/questions/26833642/… . – Mark Rotteveel Jan 6, 2017 at 11:42 I tried running command promt as adminstrator but this gave the same results. However, i followed your link and the command: "start> CMD> c:\Program Files\MySQL Server 5.7\bin> mysql -u root -p" did the trick! – Fane Fonseka Jan 6, 2017 at 11:58

command for password reset (if required)

Make sure that your file is in C: drive. root folder.

Then execute the below command:

C:\> cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
C:\> mysqld --init-file=C:\\mysql-init.txt
                pacoverflow it seems that the data folder was required. However to finally change the root password for mysql workbench I simply opened up the program and under Management > Users and Privileges. I selected root and changed the password. I stopped services, closed workbench and started services again and opened workbench again. Entered the new password and 'Stored to Vault'. New password works and all is well in mysql land.
– Dupls
                Feb 20, 2020 at 1:49
                @Asqan, It happened to me also, then I went to services.msc  in windows, from there I clicked MySQL 8 and started it( it was on manual) , also I set it to automatic so it starts every time windows start, now it's working.
– Ali 
                May 15, 2020 at 11:11

As mentioned above, create a "data" folder, (for me after that it didn't show errors, but it wasn't stills starting).
After that, go to services.msc in windows and start it from there. Also set it to Automatic so it starts automatically whenever you start the windows. It worked for me.

If you install MySQL using the MySQL installation wizard your executable path is where you installed. It's something like "C:\Program Files\MySQL\MySQL Server 8.0\bin". Your my.init file resides in ProgramData, and path for init file may be like "C:\ProgramData\MySQL\MySQL Server 8.0". If it's can't be viewed in the location, please check whether it's hide.

As in your error description "Can't create test file C:\Program Files\MySQL\MySQL Server 5.7\data...", It seems there is no folder named 'data' in MySQL installed location. Most probably It may reside where the 'my.init' file exists (ProgramData). Else may be the name of the folder not 'data' but 'Data'.

You can copy the Data folder from the location of init-file exist and paste to the executable location. Also, change the name of the folder to data if it's capitalized.

I ran the command bin\mysqld --initialize --console and everything was solved. In some cases the data folder should be created before. There are different parameters for windows and the rest.

See the following links:
https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html
https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html#data-directory-initialization-password-assignment
https://dev.mysql.com/doc/refman/8.0/en/option-files.html

In my case, I installed MySQL with Windows installer on the D:/ drive and was set NOT to run as Windows service. I managed to resolve the issue by moving my.ini from C:\ProgramData\MySQL\MySQL Server 8.0 to MySQL installation folder.

This error happens to me. The solution was edit D:\Program Files\xampp\mysql\data\my.ini and change the directory to your D: path

[mysqld]
datadir=D:\program files\xampp\mysql\data
[client]

I could solve it; I had similar issues.

C:\Program Files\MySQL\MySQL Server 8.0\bin>**mysqld --console**
2021-02-27T23:46:09.919345Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.23) starting as process 7296
2021-02-27T23:46:09.926583Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2021-02-27T23:46:09.926798Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2021-02-27T23:46:09.927086Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2 - No such file or directory)
2021-02-27T23:46:09.933751Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-02-27T23:46:09.934110Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.23)  MySQL Community Server - GPL.

The solution was that I needed to recreate the my.ini file in C:\ProgramData\MySQL\MySQL Server 8.0 and add to this:

[mysqld]
datadir=C:\ProgramData\MySQL\MySQL Server 8.0\Data

Set encoding to ANSI and saved the file.

Then the service could start:

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" MySQL80

Installing with a new MSI installer also didn't solve the issue, it kept hanging until I made the above mentioned adaptations.

C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" was what I needed to do from an Administrative cmd prompt. – Tim Nov 22, 2021 at 2:20

For xampp-portable-windows-x64-8.0.8-0-VS16 It worked by just putting at root of drive as mentioned in \ xampp \ readme_en.txt

NOTE: Unpack the package to your USB stick or a partition of your choice.
There it must be on the highest level like E:\ or W:\.

Hopes that helps

I stumbled on the same problem as mentioned at the beginning of this thread, and the trick for me was to run my console on Administrator mode (windows). The error messages related to things like "can't find the folder" etc.., were due to the unability for the program to create, on demand, such folders and files. Cheers

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.