每次重新启动后,datadir的所有权将重置为mysql:mysql [英] Ownership of datadir is reset to mysql:mysql after every reboot
问题描述
我正在Manjaro 5.10.23-1上使用MariaDB 10.5.9-1.
I'm using MariaDB 10.5.9-1 on Manjaro 5.10.23-1.
我使用以下命令初始化了mariadb数据库目录:
I initialized mariadb database directory using this command:
$ sudo mariadb-install-db --user=shaouai --basedir=/usr --datadir=/var/lib/mysql
数据目录初始化后,/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
还有一个目录/run/mysqld
,默认情况下,当服务器启动并运行时,文件 mysqld.sock
驻留在该目录中,该目录具有权限和所有权:>
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/
我不知道何时创建/run/mysqld
,也许是服务器第一次成功启动.
I have no idea when /run/mysqld
was created, maybe the first time server started successfully.
mysqld_safe --datadir =/var/lib/mysql
可以成功启动服务器.
mysqld_safe --datadir=/var/lib/mysql
can start server successfully.
但是问题是,每次重新启动后,/var/lib/mysql
和/run/mysqld
的权限和所有权都重置为 mysql:mysql
:
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/
因此,由于各种权限被拒绝",MariaDB服务器无法启动.
Thus due to various "permission denied", MariaDB server failed to start.
有一个问题与我的完全相同.
There's one question totally the same as mine.
此处是 systemctl cat mariadb.service
的完整输出
推荐答案
我不确定您为什么更改用户.这可能不是一个好主意.但是假设有充分的理由,请在下面说明您的情况:
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:
看起来mysqld_safe可能已经更改了权限.如果您以这种方式进行测试,请在参数中添加-user = shaouai
.
It looks like the mysqld_safe may have changed the permissions. If you start this way for testing add --user=shaouai
to the arguments.
要允许systemd默认以用户 shaouai
To allow systemd to default start as the user shaouai
systemctl编辑mariadb.service
添加:
[Service]
User=shaouai
Group=shaouai
然后:
chown -R shaouai: /var/lib/mysql /run/mysqld/
然后 systemctl重新启动mariadb.service
.
这将以该用户而不是默认的 mysql
用户的身份启动服务.
This will start the service as this user instead of the default mysql
user.
这篇关于每次重新启动后,datadir的所有权将重置为mysql:mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!