每次重新启动后,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
可以成功启动服务器.
但问题是,每次重启后,/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/
因此由于各种permission denied",MariaDB server 启动失败.
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 restart mariadb.service
.
这将以该用户而不是默认的 mysql
用户身份启动服务.
This will start the service as this user instead of the default mysql
user.
这篇关于每次重新启动后,datadir 的所有权都会重置为 mysql:mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!