Explain Codes LogoExplain Codes Logo

Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root

sql
database-configuration
security-best-practices
mysql-configuration
Nikita BarsukovbyNikita Barsukov·Nov 25, 2024
TLDR

To rectify the mysqld root user error quickly, edit the MySQL config file. Open /etc/mysql/mysql.conf.d/mysqld.cnf, add user=mysql under the [mysqld] section, and restart MySQL using this command: sudo systemctl restart mysql. Here's what that addition looks like:

[mysqld] # Adding Linux MySQL user to avoid future misunderstandings user=mysql

Remember: Running MySQL as root is a security risk.

Decoding the error message

The error ordinarily surfaces after an OS upgrade such as switching to OS X Yosemite. It's an indication that the mysqld daemon is attempting to run with root privileges, which isn't secure.

Assigning appropriate user permissions

To ensure security, do not use the system's root user for the MySQL daemon. Instead, use MySQL's root user, who is delegated specific privileges to handle MySQL operations.

Proper steps to start and stop the server

To start the MySQL server error-free, use the following command:

# "Knock, Knock." # "Who's there?" # "sudo command asking MySQL server to start." sudo /usr/local/mysql/support-files/mysql.server start

And when it comes to graceful termination, use mysqladmin shutdown instead of killing the mysqld process, to avoid unexpected consequences.

When the normal procedure doesn't cut it

If the usual sudo systemctl restart mysql command fails, fallback on sudo service mysqld restart. It's particularly useful for Amazon Linux AMI or CentOS.

If you stumble upon warnings concerning timestamps and table names, check if your server configurations are up to par. Ensure, for instance, that your my.cnf file accommodates server startup and table names are case-insensitive, if your system needs it.

[mysqld] # Making the table names case-insensitive, just like some people with their regard to grammar! lower_case_table_names=1

Importance of security post startup

Don't limit security measures to the startup process. Change default passwords and examine all access rights. MySQL documentation will guide you through database fortification.