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

I installed a MySQL server with installer and it started. After reboot I tried to start it again and get the error:
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 -p as administrator, nothing happens.

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

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.
Instead of running mysqld.exe from the command line,
Win + R
Run services.msc
Right-click on MySQL57
Start the service.

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 mysqld command from the command prompt, I had to specify the data directory manually:
mysqld --datadir=D:/MySQLData/Data
Here's the documentation for mysqld command-line arguments.

First run
mysqld -u root --initialize-insecure
It will create data folder with root as user without password. Then run
mysqld.exe -u root --console

What I did (Windows 10) for a new installation:
Start cmd in admin mode (run as administrator by hitting windows key, typing cmd, right clicking on it and selecting "Run as Administrator"
Change into "MySQL Server X.Y" directory (for me the full path is C:\Program Files\MySQL\MySQL Server 5.7")
using notepad create a my.ini with a mysqld section that points at your data directory
[mysqld]
datadir="X:\Your Directory Path and Name"
created the directory identified in my.ini above.
change into bin Directory under server directory and execute:
mysqld --initialize
Once complete, started the service and it came up fine.

Check that the director exists.
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.
If this is stil not working try having the following notation with double slashes: C:\WebSerer\MySQL\data or C:/WebServer/MySQL/data

If you are having this issue and can't find the MySQL service either, just launch "MySQL Installer" from the Start menu (or download it), then choose "Reconfigure" on MySQL Server. Follow the steps to set a root user password and then the service will be created and started automatically (and set to auto-start on boot).

In mysql 8.0.13 zip package initializing.
Verify that data folder is empty.
Under the mysql bin path run
mysqld.exe --initialize-insecure
Add to my.ini native mysql
[mysqld]
default_authentication_plugin=mysql_native_password

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
I solved it by
Copy my.ini from "C:\ProgramData\MySQL\MySQL Server X.Y\my.ini"
Paste it in "C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
Restart MySQL Server from services.msc
In the .ini file, their is part that reads:
# 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".

Check your real my.ini file location and set --defaults-file="location" with this command
mysql --defaults-file="C:\MYSQL\my.ini" -u root -p
This solution is permanently for your cmd Screen.

remove all files in "{path-to-mysql}\data" directory and run:
mysqld --initialize-insecure --basedir={path-to-mysql}\mysql --datadir={path-to-mysql}\data --console

I don't know if it's your problem but try this...
For me, the version of my.ini which is created under "ProgramData\MySQL\MySQL Server [version]" wasn't read. I had to move it to "Program Files\MySQL\MySQL Server [version]".
RTS.

If you installed MySQL Server using the Windows installer and as a Window's service, then you can start MySQL Server using PowerShell and experience the convenience of not leaving the command line.
Open PowerShell and run the following command:
Get-Service *sql*
A list of MySQL services will be retrieved and displayed. Choose the one that you want and run the following command while replacing service-name with the actual service name:
Start-Service -Name service-name
Done. You can check that the service is running by running the command Get-Service *sql* again and checking the status of the service.

mariofertc completely solved this for me here are his steps:
Verify mysql's data directory is empty (before you delete it though, save the err file for your records).
Under the mysql bin path run:
mysqld.exe --initialize-insecure
add to my.ini (mysql's configuration file) the following:
[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.
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

This solution uses the windows mysql installer.
I have tried every other way mentioned here and other related posts, but it did not solve my problem, the service just wont start, but the below approach with the mysql-installer did.
If you still have your installer or atleast remember the version then follow below steps:
Start your windows mysql installer. For me it was "mysql-installer-community-8.0.20.0"
Then remove/uninstall the SQL Server and remove all configurations
Manually delete the SQL Server folder from "C:\Program Files\MySQL\MySQL Server 8.0."
Start your mysql installer again and install the SQL Server again
You can check from the window's services that the MySqL Server has started.
Hope it helps someone.

Check for missing folders that are required by the server, in my case it was UPLOADS folder in programData which was deleted by empty folder cleaner utility that I used earlier.
How did I find out:
run the server config file my.ini(in my case it was in programData) as the defaults-file param for mysqld (don't forget to use --console option to view error log on screen)
'mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console'
Error:
mysqld: Can't read dir of 'C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\' (OS errno 2 - No such file or directory)
Solution:
Once I manually created the Uploads folder the server started successfully.

In my case, I'm MySQL5.6, install by workbrench install tools in Win10 pro.
there are two configuration file need to modify,
only edit the line: datadir=E:\MySQL
stop MySQL56 service using services.msc
edit my.ini under C:\ProgramData\MySQL\MySQL Server 5.6
edit my-default.ini under C:\Program Files\MySQL\MySQL Server 5.6
copy C:\ProgramData\MySQL\MySQL Server 5.6*.* to E:\MySQL
start MySQL56 service using services.msc
test: create database 'testdb';
It's successed if found testdb folder exist in E:\MySQL.

Related

MySql 8 installation on widows: Database initialization failed, Empty value for 'open_files_limit' specified

I was installing mysql server for a course, and I can't install it, please help.
Beginning configuration step: Initializing database (may take a long time)
Attempting to run MySQL Server with --initialize-insecure option...
Starting process for MySQL Server 8.0.31...
Starting process with command: C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
- ---
- " --console --initialize-insecure=on --lower-case-table-names=1...
Using jemalloc.dll for my_malloc and ut::malloc etc.
C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Empty value for 'open_files_limit' specified.
Process for mysqld, with ID 7496, was run successfully and exited with code 1.
Failed to start process for MySQL Server 8.0.31.
Database initialization failed.
Ended configuration step: Initializing database (may take a long time)**
enter image description here
enter image description here
I've had the same problem, in my case I don't need the newest version, so to solve the problem i've had to download a Mysql Comunity Installer old version 5.7.27 to install the Mysql Server 5.7. Give it a try :)
In my case I could finally install it by:
Uninstalll everything
Restarted the system
Removed [ProgramData]\MySql folder
[Program Files (x86)]\MySql folder
Run the installer again
Skipped installer update
And installation succeed!
I am running windows 11 and installed version 8.0.31 with developer config.

The used command is not allowed again

Windows 10/MySQL8.0/R/RStudio
I'm running MySQL as a Windows service.
I've read a couple of related post on this site the evening.
I created my.cnf file as suggested:
[mysql]
local-infile
I've the cnf file in The same directory as the exec., in the MySQL/etc directory, in my home directory and finally in C:\
What am I overlooking?
The key to resolving this issue is that I'm running MySQL as a Windows service. Windows services are managed by the services.msc program.
MySQL entry in services manager:
C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini"
All we have to do is in the my.ini (remember in Windows config files are *.ini):
[mysqld]=1
local-infile=1

MySQL 8.0 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno 2 - No such file or directory) - can't find data for db from cmd

So, I'm looking to start a MYSQL server using CMD, and do some small simple tasks on it (hence why I'm using it that way and not a GUI)
I was told the best method for this, would be to run this command:
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --console --standalone
Which I did, however, I am getting this error:
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --console --standalone
mysqld: Can't change dir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\'
(OS errno 2 - No such file or directory)
2018-10-30T17:43:27.385678Z 0 [System] [MY-010116] [Server] C:\Program
Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.12) starting as
process 4676
2018-10-30T17:43:27.420966Z 0 [Warning] [MY-010091] [Server] Can't create
test file C:\Program Files\MySQL\MySQL Server 8.0\data\DESKTOP-
HITD28G.lower-test
2018-10-30T17:43:27.421409Z 0 [Warning] [MY-010091] [Server] Can't create
test file C:\Program Files\MySQL\MySQL Server 8.0\data\DESKTOP-
HITD28G.lower-test
2018-10-30T17:43:27.423273Z 0 [ERROR] [MY-010172] [Server] failed to set
datadir to C:\Program Files\MySQL\MySQL Server 8.0\data\
2018-10-30T17:43:27.434694Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-10-30T17:43:27.442047Z 0 [System] [MY-010910] [Server] C:\Program
Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld
8.0.12) MySQL Community Server - GPL.
I have MySQL 8.0 installed, with the server, workbench etc, but apparently the data isn't there.
Have I installed it wrongly then?
While installing MySQL 8.0 via Windows Installer, in the configuration step, the installer puts the configuration file my.ini at location C:\ProgramData\MySQL\MySQL Server 8.0 and sets the variable defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini for mysqld command.
defaults-file just points to the file from where the server reads the default configuration settings when it actually gets started. Read more here.
Now, there are actually two ways to start the server without the GUI requirement.
Method 1: Running the server using installed Windows service
Either start, stop and restart the MySQL80 service through Services app or use net commands in cmd to do the same.
(As pointed out by #nonNumericalFloat)
Method 2:
(This actually worked for me)
The MySQL80 service starts the mysqld.exe executable which actually points to the configuration file, my.ini and to the defaults-file variable as evident by the Path to executable field under the Properties tab of the service.
So using the mysqld command alone is not sufficient as it neither provides the path to the default option file needed by the server during startup which the MySQL80 service provides (as described before) nor it provides the right location of data folder (which is also specified within my.ini by datadir) . Thus, the right command to run the server is as follows:
mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console
Also, because when mysqld is used alone, it tries to find the data folder in C:\Program Files\MySQL\MySQL Server 8.0\data which actually is not present, instead of setting defaults-file, datadir can be set to point to the right data folder location using the following command:
mysqld --datadir="C:\ProgramData\MySQL\MySQL Server 8.0\Data" --console
(Similar workaround mentioned by keerthiprasath)
console parameter is used to show any error and/or status messages while the command is being executed.
Another point to note that within the my.ini file, it is specified that under "Installation Instructions",
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y).
So after copying my.ini file from C:\ProgramData\MySQL\MySQL Server 8.0 to C:\Program Files\MySQL\MySQL Server 8.0, mysqld --console alone works fine.
Note:
Commands in method 2 only works when cmd is granted with administrative privileges.
Also, PATH needs to be set for easier invocations of the MySQL programs.
I was facing the same problem; Apparently, after shutting down my server I was not able to start it anymore.
The Server itself was installed as a service - named "mysql" by default. I did not remember renaming it to something else, so I could not start the right service.
Try installing it as a service
Start cmd
Go to the "C:\Program Files\MySQL\MySQL Server 5.6\bin"
type mysqld --install
then start the service:
METHOD #1: Access the Installed Service
Open up the Services app in the Control Panel &
Scroll alphabetically to the MySQL service:
Right click the service
Click Start Service
METHOD #2: Command Line Execution
Open DOS Window From the C: Prompt and run this:
net start mysql or net start mysql57. The right name may
vary on your system
For further information on installing or removing the service check the MySQL docs.

Can't create test file lower test start server mysql

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?
Create a data folder in C:\Program Files\MySQL\MySQL Server 8.0.
Create a new file with
(ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';)
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
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.
In my case, the data folder did not exists, so I created one and things started working.
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
That happened to me when I try to launch the server without being in admin mode. Try relaunching console in admin mode and then navigate to the sql server 8.0 directory before trying again

MySQL said: 2002 - No connection could be made because the target machine actively refused it

Also the error message in xampp control panel states:
Found Path: "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.5\my.ini" MySQL
20:08:20 [mysql]
Expected Path: c:\xampp\mysql\bin\mysqld.exe --defaults-file=c:\xampp\mysql\bin\my.ini mysql
Can you help as this is a fresh install of xampp v.3.2.1
I followed the instructions on install I don't know why it's not working.
Do I need to change the path in the httpd.conf file in mysql for it to find the path?
It looks mysql is already installed in your system in the above mentioned "Found Path". If already installed mysql is not needed, uninstall it. Now try to run our new Xampp mysql server, it will run. Otherwise you can run the xampp mysql using "mysql_start" batch file which is under XAMPP folder.