AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 212323
Accepted
wellwellwell
wellwellwell
Asked: 2018-07-17 06:40:34 +0800 CST2018-07-17 06:40:34 +0800 CST 2018-07-17 06:40:34 +0800 CST

更改datadir后无法启动mysqld服务

  • 772

我有一个安装了 RHEL 7 的 AWS EC2mysql-5.5实例xvda。它datadir在下面/var/lib/mysql(默认情况下)。

我正在从版本 5.5.29 的数据库中导入转储,当前安装的版本是 5.5.60

由于空间不足xvdf并将其安装在/data_drive

然后按照以下步骤更改数据目录:

  • 停止mysqld并验证它是否已停止
  • 用于rsync -av /var/lib/mysql /data_drive移动具有权限的文件夹
  • 将旧的 mysql 数据目录移动到xvda(原始卷)上的备份文件
  • 编辑/etc/my.cnf以更改[mysqld]块以反映两者中的新datadir位置socket

    datadir=/data_drive/mysql socket=/data_drive/mysql/mysql.sock

  • 在文件末尾添加了客户端块

    [client] port=3306 socket=/data_drive/mysql/mysql.sock

  • 保存文件,然后尝试以mysqldroot 用户和非 root 用户身份重新启动服务,但它不会启动。

以下是/var/log/mysqld.log相关时间戳的输出:

180713 19:27:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
180713 20:20:37 mysqld_safe Logging to '/var/log/mysqld.log'.
180713 20:20:37 mysqld_safe Starting mysqld daemon with databases from /data_drive/mysql
180713 20:20:37 [Warning] Can't create test file /data_drive/mysql/ip-10-0-0-180.lower-test
180713 20:20:37 [Note] /usr/sbin/mysqld (mysqld 5.5.60) starting as process 18669 ...
180713 20:20:37 [Warning] Can't create test file /data_drive/mysql/ip-10-0-0-180.lower-test
180713 20:20:37 [Warning] Can't create test file /data_drive/mysql/ip-10-0-0-180.lower-test
180713 20:20:37 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
180713 20:20:37 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
180713 20:20:37 InnoDB: The InnoDB memory heap is disabled
180713 20:20:37 InnoDB: Mutexes and rw_locks use GCC atomic builtins
180713 20:20:37 InnoDB: Compressed tables use zlib 1.2.3
180713 20:20:37 InnoDB: Using Linux native AIO
180713 20:20:37 InnoDB: Initializing buffer pool, size = 128.0M
180713 20:20:37 InnoDB: Completed initialization of buffer pool
180713 20:20:37  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.

当我运行sudo mysql_upgrade它时,它给出了以下输出:

Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Error: Failed while fetching Server version! Could be due to unauthorized access.
FATAL ERROR: Upgrade failed

这是当前/data_drive/mysql目录的样子:

[ec2-user@ip-10-0-0-180 mysql]$ ls -al /data_drive/mysql/
total 5921812
drwxr-xr-x. 4 mysql    mysql       4096 Jul 13 18:45 .
drwxr-xr-x. 5 ec2-user root        4096 Jul 13 18:46 ..
-rw-rw----. 1 mysql    mysql 6053429248 Jul 13 18:45 ibdata1
-rw-rw----. 1 mysql    mysql    5242880 Jul 13 18:45 ib_logfile0
-rw-rw----. 1 mysql    mysql    5242880 Jul 13 18:35 ib_logfile1
drwx------. 2 mysql    root        4096 Jul 12 19:42 mysql
drwx------. 2 mysql    mysql       4096 Jul 12 19:42 performance_schema
mysql linux
  • 2 2 个回答
  • 10044 Views

2 个回答

  • Voted
  1. Best Answer
    dbdemon
    2018-07-17T07:38:39+08:002018-07-17T07:38:39+08:00

    这可能是 SELinux 的问题。如果 SELinux 以强制模式运行,则需要说服它允许 mysqld 使用非默认数据目录。或者,将 SELinux 置于许可模式,或完全禁用它。运行sestatus以查看当前运行的模式。运行grep mysql /var/log/audit/audit.log以查看 SELinux 是否阻止了任何 mysql 文件访问尝试或类似的尝试。(但请注意,如果在许可模式下运行,这很好,因为它实际上不会阻止任何内容,它只是记录如果您在强制模式下运行会阻止的内容。)

    运行setenforce permissive以将 SELinux 置于许可模式,但请注意您需要编辑/etc/sysconfig/selinux(或/etc/selinux/config)以使更改永久生效。

    如果您尝试说服 SELinux 允许新的数据目录,则需要确保为文件保留 SELinux 上下文。我怀疑在使用 rsync 时这可能会丢失,但不确定。

    这里有一个页面详细解释了在移动 MySQL 数据目录时如何处理 SELinux:如何在 CentOS 和 Ubuntu 上移动 MySQL 数据目录

    • 3
  2. William Xu
    2019-08-10T07:20:17+08:002019-08-10T07:20:17+08:00

    还要确保 /data_drive/mysql 具有正确的权限和所有权。例如,在我的 RHEL 7.6 VM 中,我需要执行以下操作:

    chown root:root /data_drive
    chown mysql:mysql /data_drive/mysql
    
    • 2

相关问题

  • 是否有任何 MySQL 基准测试工具?[关闭]

  • 我在哪里可以找到mysql慢日志?

  • 如何优化大型数据库的 mysqldump?

  • 什么时候是使用 MariaDB 而不是 MySQL 的合适时机,为什么?

  • 组如何跟踪数据库架构更改?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve