Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

mysqld will not start after a generic binary install

ErrorFailed 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.

  • Applies to MySQL 8.4, Linux generic binary tarball
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/data
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The folder is missing or empty, and the server was started straight after unpacking the archiveThe data directory was never initializedFix
    3. 3Errcode 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

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/data

3Verify

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

Did this fix it?

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).err

2Fix

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=mysql

3Verify

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

Did this fix it?

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/data

2Fix

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/data

3Verify

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).err

Confirmed by dev.mysql.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.