Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

mysqld cannot create binlog.index: OS errno 13, Permission denied

Errormysqld: File '.\binlog.index' not found (OS errno 13 - Permission denied)

Short answer

Errno 13 means the account that started mysqld may not write in the data directory. binlog.index is just one of the files the server must create there, because binary logging is on by default and its files live in that directory. Fix access to the whole data directory, start the server the way the manual's Windows reset procedure describes, and check security software.

  • Applies to MySQL 8.4, Windows, Linux
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the last lines of the error log. It sits in the data directory and is named after the host. Note whether files other than binlog.index are refused too.

    tail host_name.err
    # on Windows, open host_name.err in the data directory with a text editor
  2. 2Match what you see, then jump to its fix

    1. 1Permission denied for binlog.index and for other files in the same data directoryThe data directory is not owned by, or not open to, the account that starts mysqldFix
    2. 2The MySQL service starts fine, and the error only appears when you run mysqld yourself from a consoleA one-off start for a password reset skipped the steps of the Windows procedureFix
    3. 3Ownership and permissions are correct and errno 13 still appearsSecurity software blocks mysqld from the data directoryFix

What does the error look like?

  • mysqld: File '.\binlog.index' not found (OS errno 13 - Permission denied)
  • Errcode 13 (Permission denied)

Cause 1 of 3

The data directory is not owned by, or not open to, the account that starts mysqld

1Check

Binary logging is on by default in MySQL 8.4 and the binary log files and index go into the data directory, so binlog.index is one of the files the server must create there. The manual says Errcode 13 means the privileges of the data directory or its contents do not permit server access. A server once started as root can leave root-owned files in the data directory, and the normal server account cannot use those.

# Linux or macOS; use your own data directory path
ls -la /usr/local/mysql/var

2Fix

Give the account that runs mysqld ownership of the data directory and everything in it. Do not solve it by running the server as root. On Windows, change the permissions of the data folder and its contents so that the account that starts mysqld may use them.

chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/var

3Verify

Start the server again and connect to it.

mysql -u root -p -e "SELECT CURRENT_USER();"

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 3

A one-off start for a password reset skipped the steps of the Windows procedure

1Check

The manual's Windows procedure for resetting the root password begins with logging on to the system as Administrator. For a server installed with the installer it also passes the real option file with --defaults-file, so that the server uses the data directory from that file. A server started without both can end up with a data directory it may not write.

cd "C:\Program Files\MySQL\MySQL Server 8.4\bin"
dir "C:\ProgramData\MySQL\MySQL Server 8.4\my.ini"

2Fix

Stop the service first. Then, logged on as Administrator, start mysqld with the option file and the init file, as the manual shows, and delete the init file afterwards. Stop that server and start the service normally.

mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.4\\my.ini" --init-file=C:\\mysql-init.txt

3Verify

After the restart as a service, log in with the new password.

mysql -u root -p -e "SELECT CURRENT_USER();"

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 3

Security software blocks mysqld from the data directory

1Check

The manual warns that MySQL can fail to start, even with correct ownership, when other security software manages application access to parts of the file system.

tail host_name.err
# on Windows, open host_name.err in the data directory with a text editor

2Fix

Reconfigure that software so that mysqld may use the directories it needs in normal operation. Then start the server again.

NET START mysqld_service_name

3Verify

The server starts and binlog.index appears in the data directory.

dir "C:\path\to\data" | findstr /i "binlog"

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Run MySQL as a service, and avoid launching mysqld by hand except for recovery.
  • When you start the server as root on Linux, always add --user=mysql, so it creates no root-owned files in the data directory.
  • Keep the data directory path in the option file, and point one-off commands at that file with --defaults-file.
  • Keep the data directory and all its files owned by the one account that runs the server.

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.