Skip to content
Advertisement

Ownership of datadir is reset to mysql:mysql after every reboot

I’m using MariaDB 10.5.9-1 on Manjaro 5.10.23-1.

I initialized mariadb database directory using this command:

$ sudo mariadb-install-db --user=shaouai --basedir=/usr --datadir=/var/lib/mysql

After data directory initialization, permissions and ownership of /var/lib/mysql:

$ ls -ld /var/lib/mysql
drwx------ 5 shaouai root 4096 Apr 10 00:08 mysql
$ ls -lh /var/lib/mysql
total 109M
-rw-rw---- 1 shaouai shaouai  24K Apr 10 00:08 aria_log.00000001
-rw-rw---- 1 shaouai shaouai   52 Apr 10 00:08 aria_log_control
-rw-rw---- 1 shaouai shaouai  972 Apr 10 00:08 ib_buffer_pool
-rw-rw---- 1 shaouai shaouai  12M Apr 10 00:08 ibdata1
-rw-rw---- 1 shaouai shaouai  96M Apr 10 00:08 ib_logfile0
drwx------ 2 shaouai shaouai 4.0K Apr 10 00:08 mysql
drwx------ 2 shaouai shaouai 4.0K Apr 10 00:08 performance_schema
drwx------ 2 shaouai shaouai 4.0K Apr 10 00:08 test

And there’s one another directory /run/mysqld, which file mysqld.sock resides in by default when server is up and running, has permissions and ownership:

$ ls -ld /run/mysqld/
drwxr-xr-x 2 shaouai shaouai 60 Apr 10 08:31 /run/mysqld/

I have no idea when /run/mysqld was created, maybe the first time server started successfully.

mysqld_safe --datadir=/var/lib/mysql can start server successfully.

But the problem is, after every reboot, the permissions and ownership of /var/lib/mysql and /run/mysqld was reset to mysql:mysql :

$ ls -ld /var/lib/mysql
drwx------ 5 mysql mysql 4096 Apr 10 00:08 mysql
$ ls -lh /var/lib/mysql
total 109M
-rw-rw---- 1 shaouai shaouai  24K Apr 10 00:08 aria_log.00000001
-rw-rw---- 1 shaouai shaouai   52 Apr 10 00:08 aria_log_control
-rw-rw---- 1 shaouai shaouai  972 Apr 10 00:08 ib_buffer_pool
-rw-rw---- 1 shaouai shaouai  12M Apr 10 00:08 ibdata1
-rw-rw---- 1 shaouai shaouai  96M Apr 10 00:08 ib_logfile0
drwx------ 2 shaouai shaouai 4.0K Apr 10 00:08 mysql
drwx------ 2 shaouai shaouai 4.0K Apr 10 00:08 performance_schema
drwx------ 2 shaouai shaouai 4.0K Apr 10 00:08 test
$ ls -ld /run/mysqld/
drwxr-xr-x 2 mysql mysql 60 Apr 10 08:31 /run/mysqld/

Thus due to various “permission denied”, MariaDB server failed to start.

There’s one question totally the same as mine.

Here is full output of systemctl cat mariadb.service.

Advertisement

Answer

I’m not sure why you changed the user. It may not be a good idea. But assuming there is a good reason, below explains your situtation:

It looks like the mysqld_safe may have changed the permissions. If you start this way for testing add --user=shaouai to the arguments.

To allow systemd to default start as the user shaouai

systemctl edit mariadb.service

Add:

[Service]
User=shaouai
Group=shaouai

Then:

chown -R shaouai: /var/lib/mysql /run/mysqld/

Then systemctl restart mariadb.service.

This will start the service as this user instead of the default mysql user.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement