MySQL 无法通过 Datadir 更改启动

MySQL 无法通过 Datadir 更改启动

我正在尝试更改datadirmysql。当我尝试重新启动服务时,它会挂起 10 分钟,然后无法重新启动。以下是我更改目录的步骤:

  1. sudo 服务 mysqld 停止
  2. sudo cp -R -p /var/lib/mysql /srv/msqyl2
  3. ls -lha /srv/mysql2

    drwxr-xr-x. 4 mysql mysql 4.0K 8月 24 17:51 msqyl2

  1. sudo vim /etc/my.cnf
  2. 注释掉默认目录 `#datadir=/var/lib/mysql`
  3. 添加一个具有相同指令但新位置的新行,`datadir=/srv/mysql2`
  4. sudo 服务 mysql 启动

这给了我:

由于超出超时时间,mysqld.service 作业失败。有关详细信息,请参阅“systemctl status mysqld.service”和“journalctl -xe”。

处理大约 10 分钟后start。如果我反转注释,使目录成为默认目录,则重新启动将在 <5 秒内完成。

带回journalctl -xe

Aug 24 18:35:17 uroot-ARTMO-myserver-1 systemd[1]: mysqld.service start-post operation timed out. Stopping.
Aug 24 18:35:17 uroot-ARTMO-myserver-1 systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has failed.
-- 
-- The result is failed.
Aug 24 18:35:17 uroot-ARTMO-myserver-1 systemd[1]: Unit mysqld.service entered failed state.
Aug 24 18:35:18 uroot-ARTMO-myserver-1 systemd[1]: mysqld.service failed.
Aug 24 18:35:18 uroot-ARTMO-myserver-1 polkitd[1309]: Unregistered Authentication Agent for unix-process:22433:121785532 (system bus name :1.833, object path /org/freedesktop/PolicyKi
Aug 24 18:35:18 uroot-ARTMO-myserver-1 systemd[1]: mysqld.service holdoff time over, scheduling restart.
Aug 24 18:35:18 uroot-ARTMO-myserver-1 systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has begun starting up.
Aug 24 18:35:18 uroot-ARTMO-myserver-1 mysqld_safe[24090]: 160824 18:35:18 mysqld_safe Logging to '/var/log/mysqld.log'.
Aug 24 18:35:18 uroot-ARTMO-myserver-1 mysqld_safe[24090]: 160824 18:35:18 mysqld_safe Starting mysqld daemon with databases from /srv/mysql2
Aug 24 18:35:18 uroot-ARTMO-myserver-1 mysqld_safe[24090]: 160824 18:35:18 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

带回systemctl status mysqld.service

● mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: activating (start-post) since Wed 2016-08-24 18:45:18 CEST; 8min ago
  Process: 26133 ExecStart=/usr/bin/mysqld_safe (code=exited, status=0/SUCCESS)
  Process: 26120 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 26133 (code=exited, status=0/SUCCESS);         : 26134 (mysql-systemd-s)
   CGroup: /system.slice/mysqld.service
           └─control
             ├─26134 /bin/bash /usr/bin/mysql-systemd-start post
             └─27942 sleep 1

Aug 24 18:45:18 uroot-ARTMO-myserver-1 systemd[1]: Starting MySQL Community Server...
Aug 24 18:45:18 uroot-ARTMO-myserver-1 mysqld_safe[26133]: 160824 18:45:18 mysqld_safe Logging to '/var/log/mysqld.log'.
Aug 24 18:45:18 uroot-ARTMO-myserver-1 mysqld_safe[26133]: 160824 18:45:18 mysqld_safe Starting mysqld daemon with databases from /srv/mysql2

默认目录的权限/var/lib/mysql是:

drwx------. 2 mysql mysql 4.0K 8月18日 21:32 mysql

具有mysqld.log

160824 18:35:18 mysqld_safe Starting mysqld daemon with databases from /srv/mysql2
2016-08-24 18:35:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-24 18:35:18 0 [Note] /usr/sbin/mysqld (mysqld 5.6.32) starting as process 24253 ...
2016-08-24 18:35:18 24253 [Warning] Can't create test file /srv/mysql2/uroot-ARTMO-myserver-1.lower-test
2016-08-24 18:35:18 24253 [Warning] Can't create test file /srv/mysql2/uroot-ARTMO-myserver-1.lower-test
2016-08-24 18:35:18 24253 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2016-08-24 18:35:18 24253 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

2016-08-24 18:35:18 24253 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied)
2016-08-24 18:35:18 24253 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2016-08-24 18:35:18 24253 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-08-24 18:35:18 24253 [Note] InnoDB: The InnoDB memory heap is disabled
2016-08-24 18:35:18 24253 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-08-24 18:35:18 24253 [Note] InnoDB: Memory barrier is not used
2016-08-24 18:35:18 24253 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-08-24 18:35:18 24253 [Note] InnoDB: Using Linux native AIO
2016-08-24 18:35:18 24253 [Note] InnoDB: Using CPU crc32 instructions
2016-08-24 18:35:18 24253 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-08-24 18:35:18 24253 [Note] InnoDB: Completed initialization of buffer pool
2016-08-24 18:35:18 7f32872e8740  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.
2016-08-24 18:35:18 24253 [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
2016-08-24 18:35:18 24253 [ERROR] InnoDB: The system tablespace must be writable!
2016-08-24 18:35:18 24253 [ERROR] Plugin 'InnoDB' init function returned error.
2016-08-24 18:35:18 24253 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-08-24 18:35:18 24253 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-08-24 18:35:18 24253 [ERROR] Aborting

2016-08-24 18:35:18 24253 [Note] Binlog end
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'partition'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_METRICS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_CMPMEM'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_CMP'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_LOCKS'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'INNODB_TRX'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'BLACKHOLE'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'ARCHIVE'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'MRG_MYISAM'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'MyISAM'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'MEMORY'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'CSV'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'sha256_password'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'mysql_old_password'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'mysql_native_password'
2016-08-24 18:35:18 24253 [Note] Shutting down plugin 'binlog'
2016-08-24 18:35:18 24253 [Note] /usr/sbin/mysqld: Shutdown complete

160824 18:35:18 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

答案1

通常这是因为 apparmor 之类的原因。检查/etc/是否有 apparmor、selinux 或任何配置文件将 mysql 限制为/var/lib/mysql

答案2

如果您在问题中发布的命令是正确的,那么您就输入错了。

sudo cp -R -p /var/lib/mysql /srv/msqyl2
ls -lha /srv/mysql2
drwxr-xr-x. 4 mysql mysql 4.0K Aug 24 17:51 msqyl2
Add a new line with same directive but new location, `datadir=/srv/mysql2`

mysql2不是msqyl2

相关内容