mysqld will not start after a generic binary install
Failed to find valid data directory.Short answer
After a generic binary install, mysqld needs three things: a data directory it can find, one that was created by mysqld --initialize, and one its user may read and write. The compiled-in default path is rarely where you unpacked the tarball. Check which path the server uses, then initialize and set the owner.
Fix it fast
1Find out which cause you have
Print the paths this mysqld would use, then look at the last lines of the error log in the data directory. Replace the base directory with the folder you unpacked into.
cd /usr/local/mysql bin/mysqld --basedir=/usr/local/mysql --verbose --help | grep -E "^(basedir|datadir)" ls -la /usr/local/mysql/data2Match what you see, then jump to its fix
- 1
The datadir printed by --verbose --help is not the folder you created, or the folder does not existThe server looks for the data directory in a different place than yoursFix - 2
The folder is missing or empty, and the server was started straight after unpacking the archiveThe data directory was never initializedFix - 3
Errcode 13 or Permission denied in the error log, often after the folder was created or copied as rootThe mysql user cannot read or write the data directoryFix
- 1
What does the error look like?
Failed to find valid data directory.[ERROR] --initialize specified but the data directory exists. Aborting.Errcode 13 (Permission denied) when starting mysqld
Cause 1 of 3
The server looks for the data directory in a different place than yours
1Check
The default data directory is fixed when the server is compiled. The tarball was unpacked somewhere else, or a symlink points to another folder. Compare the datadir from the first step with the real path.
readlink -f /usr/local/mysql
bin/mysqld --verbose --help | grep -E "^datadir"2Fix
Tell the server where things are, with --datadir or --basedir on the command line or in an option file. With --basedir alone, mysqld looks for a data folder inside it.
# /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data3Verify
The paths printed by the help command match the folders on disk.
bin/mysqld --defaults-file=/etc/my.cnf --verbose --help | grep -E "^(basedir|datadir)"Confirmed by dev.mysql.com
Cause 2 of 3
The data directory was never initialized
1Check
A generic binary archive contains no databases. The system tables are created by running the server once in initialize mode. The error log, named after your host, ends with the reason the start failed.
tail -n 20 /usr/local/mysql/data/$(hostname).err2Fix
Run the initialization once, as root with --user=mysql or as the mysql account. The server prints a temporary root password into its error output or log. If the folder already has files in it, initialization stops with the message in the symptoms, so remove or rename the folder first.
cd /usr/local/mysql
sudo bin/mysqld --initialize --user=mysql3Verify
The data directory now holds the system schema, and the server starts.
ls /usr/local/mysql/data
sudo bin/mysqld_safe --user=mysql &Confirmed by dev.mysql.com
Cause 3 of 3
The mysql user cannot read or write the data directory
1Check
The owner and permissions of the data directory and its contents must let the server read and modify them. Look at the owner of everything below it.
ls -la /usr/local/mysql/data2Fix
Give the files to the account that runs the server. Do not start the server as root to get around it. Security software that guards parts of the file system can block the server even with correct ownership.
sudo chown -R mysql /usr/local/mysql/data
sudo chgrp -R mysql /usr/local/mysql/data3Verify
Start the server again and read the end of the error log.
sudo bin/mysqld_safe --user=mysql &
tail -n 5 /usr/local/mysql/data/$(hostname).errConfirmed by dev.mysql.com
How do I stop it coming back?
- Follow the generic binary steps in order: user and group, unpack, link, the mysql-files folder with its owner, then initialize.
- Put basedir and datadir into the option file on the day you install, so a later upgrade or relocation cannot change them by surprise.
- Keep the temporary root password from the first initialization and change it with ALTER USER at once.
- Run initialization on an empty folder only, and never delete a data directory that holds databases you want to keep.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
The MySQL container stops with: the designated data directory is unusable
[ERROR] --initialize specified but the data directory exists. Aborting.
This message closes a failed first start.
3 causes, each with a fixDatabases
MySQL start fails with: the server quit without updating the PID file
Can't start server: Bind on TCP/IP port: Address already in use
This message is only a symptom: mysqld started and exited before it wrote its PID file.
3 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Locked out of a fresh MariaDB install as root on Mac or Linux
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
A fresh MariaDB root account is not a normal password account.
3 causes, each with a fix