I wanted to run mysqld
as the root user.
I'm running Ubuntu 21.04 and have installed mysql-server
.
MySQL version:
mysql Ver 8.0.25-0ubuntu0.21.04.1 for Linux on x86_64 ((Ubuntu))
Changing the file ownership to root
chown -R root /var/lib/mysql
/etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
user = root
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
datadir = /var/lib/mysql
When I start the MySQL service via:
sudo service mysql start
I am getting an error:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2021-05-25 08:29:56 PDT; 23s ago
Process: 2413 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Process: 2421 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Main PID: 2421 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 13 (Permission denied)
However, if I change the file permissions of /var/lib/mysql back to the mysql user, the service starts.
Please let me know the solution for how I can run this as root.
If I am doing anything wrong please suggest clear steps.
Ref: [1]: https://dev.mysql.com/doc/refman/8.0/en/changing-mysql-user.html
The answer is in the link you provided
So in order to run
mysqld
as root you need to install it from the tar.gz package. Then the steps you've already tried should be sufficient.https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/binary-installation.html has instructions for how to install mysql, and https://dev.mysql.com/downloads/mysql/ has the download links.
I should note that it is generally not a good idea to run
mysqld
as root. It sounds like you're aware of that, and are trying to explore the exploits that might be possible from that, but other viewers may not be as security-conscious.Normally it is not recommended to run mysql as root !!
However this is your call, your error is
Permission denied
, which means you're attempting to start the process as user/group mysql. Since you're using systemd to start the mysql service, please check the systemd service configuration:/lib/systemd/system/mysql.service
Change the User and Group to root:
Do not forget to reload the systemd demon after changes: