Glam Prestige Journal

Bright entertainment trends with youth appeal.

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]:

3

2 Answers

The answer is in the link you provided

On Linux, for installations performed using a MySQL repository or RPM packages, the MySQL server mysqld should be started by the local mysql operating system user. Starting by another operating system user is not supported by the init scripts that are included as part of the MySQL repositories.

On Unix (or Linux for installations performed using tar.gz packages) , the MySQL server mysqld can be started and run by any user.

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.

has instructions for how to install mysql, and 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:

[Service]
Type=forking
User=mysql
Group=mysql

Do not forget to reload the systemd demon after changes:

systemctl daemon-reload

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy