mysqld stops with 'Please read Security section ... run mysqld as root'
Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!Short answer
mysqld aborts when the process is root and no --user option is given. Run it as an unprivileged account instead: start the service through systemd as the mysql user, or add user=mysql to the [mysqld] group of my.cnf. Make sure that user owns the data directory.
Fix it fast
1Find out which cause you have
Find out which operating system user starts the server and whether a user= or --user setting exists.
ps -o user,cmd -C mysqld grep -rn "^user" /etc/my.cnf /etc/mysql 2>/dev/null2Match what you see, then jump to its fix
- 1
You ran mysqld or a custom start script as root (or with sudo), and the log shows the fatal message at once.mysqld was started as root with no --userFix - 2
The service worked before a manual edit or a tar.gz install, and starts as root at boot.The option file has no user= lineFix - 3
The root error is gone, but mysqld now fails to read or create files in the data directory.The data directory belongs to root after you switched userFix - 4
You installed from the MySQL repository, but start the server by hand as another user.A package init script is used with a different accountFix
- 1
What does the error look like?
Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
Cause 1 of 4
mysqld was started as root with no --user
1Check
The server code checks the effective user id. If it is 0 and no --user is set, it logs the error and exits (initialisation and help modes are exempt).
id -un2Fix
Give mysqld the account to switch to. It starts as root, then switches before accepting connections.
sudo mysqld --user=mysql3Verify
The server stays up and the process owner is the mysql user.
ps -o user,cmd -C mysqldConfirmed by dev.mysql.com
Cause 2 of 4
The option file has no user= line
1Check
The manual lets you make the choice permanent in the [mysqld] group of /etc/my.cnf or the my.cnf of the data directory.
grep -n -A3 "\[mysqld\]" /etc/my.cnf2Fix
Add the user line, then restart.
[mysqld]
user=mysql3Verify
Restart and read the process owner.
sudo systemctl restart mysql
ps -o user,cmd -C mysqldConfirmed by dev.mysql.com
Cause 3 of 4
The data directory belongs to root after you switched user
1Check
When the server runs as another user, that user must own the data directory or it cannot open databases or tables.
ls -ld /var/lib/mysql2Fix
Stop the server, give the data directory to the account, and start again. Links inside it may need their targets changed too.
sudo mysqladmin shutdown
sudo chown -R mysql /var/lib/mysql3Verify
Start the service and run a query.
sudo systemctl start mysql
mysql -e "SELECT 1"Confirmed by dev.mysql.com
Cause 4 of 4
A package init script is used with a different account
1Check
For repository or RPM installs, the manual says the init scripts expect the local mysql user and do not support another user.
getent passwd mysql2Fix
Use the packaged service (systemctl) rather than a hand-written command, and keep the account named mysql.
sudo systemctl start mysql3Verify
Check the service state.
systemctl status mysql --no-pagerConfirmed by dev.mysql.com
How do I stop it coming back?
- Never run the database as root; the manual advises against it.
- Start it only through the service manager.
- After restoring a data directory from a copy, set its owner before the first start.
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
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 fixDatabases
An Aria table fails with 'Read page with wrong checksum' (error 1030, code 176)
ERROR 1030 (HY000): Got error 176 "Read page with wrong checksum" from storage engine Aria
Code 176 means MariaDB's Aria engine read a data or index page whose checksum does not match, so that table file is damaged.
3 causes, each with a fixDatabases
The client cannot open a TCP connection to MariaDB or MySQL (error 2003)
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
Error 2003 means the client tried a TCP connection to the host and port and nobody answered.
4 causes, each with a fix