【问题标题】:MySQL: Ownership of mysql directory changes to 'mysql' from 'service_account' on linux server rebootMySQL:在 Linux 服务器重新启动时,mysql 目录的所有权从“service_account”更改为“mysql”
【发布时间】:2021-06-16 06:57:00
【问题描述】:

我正在使用适用于 Linux (x86_64) 的 MySQL 发行版 10.2.39-MariaDB。当我们最初启动它并手动配置它以正确所有权和启动时,它运行良好。但是每当我们重新启动 Linux 服务器时,'/var/lib/mysql' 的所有权就会从 'service_account' 变为 'mysql',如下所示:

Linux 服务器重启前

drwxr-xr-x. service_account service-account_grp 4096 Mar 18 14:00 mysql

Linux 服务器重启后

drwxr-xr-x. mysql mysql 4096 Mar 18 14:00 mysql

它本身改变了所有权,我碰巧没有找到它的根本原因。 我一直面临这个问题,但我无法找到解决方案。

感谢任何输入。

提前致谢,

席德

【问题讨论】:

标签: mysql linux unix mariadb file-ownership


【解决方案1】:

我写这个答案是因为我认为我们都误解了 mariadb 的User Account Management 机制。我也遇到了same problem as you,所以我在为自己写这个答案。您可以按照您实际需要的答案或danblack 进行操作。正如danblack所说,将“mysql”更改为您的service_account可能不是一个好主意。

使用 'mysql' 用户帐户初始化 mariadb 数据库目录:

$ sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
...
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
...

如您所见,创建了两个 mariadb 全权限帐户 root@localhostmysql@localhost。并且您必须是操作系统rootmysql 用户才能分别使用这两个mariadb 帐户。

然后,启用并启动 mariadb 服务器:

$ sudo systemctl enable --now mariadb.service

您可能想使用mysql_secure_installation 命令来improve the initial security

然后使用 mariadb root@localhost 帐户和系统 root 帐户连接到服务器,并使用您想要的任何名称 create new mariadb account that has root-like privileges

$ sudo mysql -u root -p  # first input your passwd to use 'sudo', then [ENTER] for empty mariadb root account passwd
[sudo] password for your_service_account:
Enter password:
...
MariaDB [(none)]> CREATE USER 'whatever_name_you_want'@'localhost' IDENTIFIED BY 'somepasswd';
Query OK, 0 rows affected (0.004 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* to 'whatever_name_you_want'@'localhost';
Query OK, 0 rows affected (0.004 sec)

MariaDB [(none)]> quit
Bye

使用新的非特权whatever_name_you_want@localhost 帐户连接到服务器并创建一个新数据库:

$ mysql -u whatever_name_you_want -p
Enter password:
...
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS mydb;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> quit
Bye

如果您为root@localhost 帐户设置密码,您甚至可以在不使用 sudo 的情况下使用此帐户:

$ sudo mysql -u root -p
[sudo] password for your_service_account:
Enter password:
...
MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('somepasswd');
Query OK, 0 rows affected (0.041 sec)

MariaDB [(none)]> quit
Bye
$ mysql -u root -p
Enter password:
...
MariaDB [(none)]> quit
Bye

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-11
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 2011-08-31
    • 1970-01-01
    • 2016-08-18
    相关资源
    最近更新 更多