从其他服务器复制文件后 MySQL 无法启动

从其他服务器复制文件后 MySQL 无法启动

最近,由于服务器故障(与 MySQL 无关),我不得不重新安装 Ubuntu 16。我现在已经重新安装了 Ubuntu 16,对于 MySQL,我已将备份文件从旧服务器上传到新安装,但无法启动。当我运行

service mysql status

我明白了

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) since Wed 2017-01-25 15:08:54 CST; 3s ago
  Process: 7872 ExecStart=/usr/bin/mysqld_safe (code=exited, status=0/SUCCESS)
  Process: 7869 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 7872 (code=exited, status=0/SUCCESS);         : 7873 (mysql-systemd-s)
   CGroup: /system.slice/mysql.service
           └─control
             ├─7873 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─8209 sleep 1

Jan 25 15:08:54 s101287 systemd[1]: Starting MySQL Community Server...
Jan 25 15:08:54 s101287 mysqld_safe[7872]: 170125 15:08:54 mysqld_safe Logging to '/var/lib/mysql/s101287.err'.
Jan 25 15:08:54 s101287 mysqld_safe[7872]: 170125 15:08:54 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

尝试启动服务器后。以下是 /var/lib/mysql 目录的 ls -la:

total 176224
drwxr-xr-x 13 mysql mysql     4096 Jan 25 15:08 .
drwxr-xr-x 48 root  root      4096 Jan 25 13:14 ..
drwxr-xr-x  2 mysql mysql    24576 Jan 25 13:59 apache
-rwxr-xr-x  1 mysql mysql       56 Jan 25 13:05 auto.cnf
drwxr-xr-x  2 mysql mysql     4096 Jan  6 04:49 banlist
drwxr-xr-x  2 mysql mysql     4096 Jan  6 04:50 daemon
-rwxr-xr-x  1 mysql mysql        0 Jan 25 13:14 debian-5.6.flag
drwxr-xr-x  2 mysql mysql     4096 Jan 25 14:12 dnttmp
-rwxr-xr-x  1 mysql mysql 79691776 Jan 25 14:54 ibdata1
-rwxr-xr-x  1 mysql mysql 50331648 Jan 25 15:08 ib_logfile0
-rwxr-xr-x  1 mysql mysql 50331648 Jan 25 14:54 ib_logfile1
drwxr-xr-x  2 mysql mysql     4096 Jan  6 04:50 multicraft_daemon
drwxr-xr-x  2 mysql mysql     4096 Jan  6 04:50 multicraft_panel
drwxr-xr-x  2 mysql mysql     4096 Jan 25 13:05 mysql
drwxr-xr-x  2 mysql mysql     4096 Jan  6 04:51 panel
drwxr-xr-x  2 mysql mysql     4096 Jan 25 13:14 performance_schema
drwxr-xr-x  2 mysql mysql     4096 Jan  6 04:51 phpmyadmin
-rw-r-----  1 mysql mysql    15651 Jan 25 15:08 s101287.err
drwxr-xr-x  2 mysql mysql     4096 Jan 16 07:02 unturned1

我查看了上述目录中的错误文件,发现文件“ibdata1”、“ib_logfile0”和“ib_logfile1”是导致问题的原因。如果我用安装全新版本的 MySQL 的原始副本替换它们,它就可以正常工作。唯一的问题是,当我尝试从数据库中加载不同的表时,它会给出“表不存在”的提示。经过进一步挖掘,我发现这个帖子这让我相信引起问题的文件是需要的。这是使用旧服务器中的文件启动服务器时的错误日志:

170125 14:59:25 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2017-01-25 14:59:25 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2017-01-25 14:59:25 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-01-25 14:59:25 0 [Note] /usr/sbin/mysqld (mysqld 5.6.28-0ubuntu0.15.04.1) starting as process 7489 ...
2017-01-25 14:59:25 7489 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2017-01-25 14:59:25 7489 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

2017-01-25 14:59:25 7489 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2017-01-25 14:59:25 7489 [Note] Plugin 'FEDERATED' is disabled.
2017-01-25 14:59:25 7489 [ERROR] Function 'innodb' already exists
2017-01-25 14:59:25 7489 [Warning] Couldn't load plugin named 'innodb' with soname 'ha_innodb.so'.
2017-01-25 14:59:25 7489 [ERROR] Function 'federated' already exists
2017-01-25 14:59:25 7489 [Warning] Couldn't load plugin named 'federated' with soname 'ha_federated.so'.
2017-01-25 14:59:25 7489 [ERROR] Function 'blackhole' already exists
2017-01-25 14:59:25 7489 [Warning] Couldn't load plugin named 'blackhole' with soname 'ha_blackhole.so'.
2017-01-25 14:59:25 7489 [ERROR] Function 'archive' already exists
2017-01-25 14:59:25 7489 [Warning] Couldn't load plugin named 'archive' with soname 'ha_archive.so'.
2017-01-25 14:59:25 7489 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-01-25 14:59:25 7489 [Note] InnoDB: The InnoDB memory heap is disabled
2017-01-25 14:59:25 7489 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-01-25 14:59:25 7489 [Note] InnoDB: Memory barrier is not used
2017-01-25 14:59:25 7489 [Note] InnoDB: Compressed tables use zlib 1.2.8
2017-01-25 14:59:25 7489 [Note] InnoDB: Using Linux native AIO
2017-01-25 14:59:25 7489 [Note] InnoDB: Using CPU crc32 instructions
2017-01-25 14:59:25 7489 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-01-25 14:59:25 7489 [Note] InnoDB: Completed initialization of buffer pool
2017-01-25 14:59:25 7489 [Note] InnoDB: Highest supported file format is Barracuda.
2017-01-25 14:59:25 7489 [Note] InnoDB: 128 rollback segment(s) are active.
2017-01-25 14:59:25 7489 [Note] InnoDB: Waiting for purge to start
InnoDB: Error: tablespace id is 219 in the data dictionary
InnoDB: but in file ./mysql/innodb_index_stats.ibd it is 2!
2017-01-25 14:59:25 7f4817fff700  InnoDB: Assertion failure in thread 139947617023744 in file fil0fil.cc line 796
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
20:59:25 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.

key_buffer_size=16777216
read_buffer_size=131072
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 76296 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x30000
/usr/sbin/mysqld(my_print_stacktrace+0x3b)[0x8e7c3b]
/usr/sbin/mysqld(handle_fatal_signal+0x36a)[0x646c0a]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10d10)[0x7f4834132d10]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7f4833560267]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7f4833561eca]
/usr/sbin/mysqld[0xa5f211]
/usr/sbin/mysqld[0xa5f3ce]
/usr/sbin/mysqld[0xa6932b]
/usr/sbin/mysqld[0xa31041]
/usr/sbin/mysqld[0xa190ac]
/usr/sbin/mysqld[0x9feed5]
/usr/sbin/mysqld[0x9a5b80]
/usr/sbin/mysqld[0x9a2807]
/usr/sbin/mysqld[0x9a42a7]
/usr/sbin/mysqld[0x972845]
/usr/sbin/mysqld[0x9c9405]
/usr/sbin/mysqld[0x9bc6c5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76aa)[0x7f48341296aa]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f4833631eed]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
170125 14:59:25 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

这两行引起了我的兴趣:

InnoDB: Error: tablespace id is 219 in the data dictionary
InnoDB: but in file ./mysql/innodb_index_stats.ibd it is 2!

如果问题出在表空间中,而另一个文件的 ID 不匹配,是否会导致此问题,或者我的理论是否陷入困境?如果我无法更改其中一个文件中的 ID,我将如何成功使用导致问题的文件,正如我所说,我需要它们才能使一半的表正常工作。

答案1

在无法使我的 MySQL 服务器工作后,我意识到我没有将整个 /var/lib/mysql 复制到新服务器上。停止 MySQL 服务器后,删除安装时生成的 /var/lib/mysql,我复制了旧文件并成功启动了服务器。将两个副本之间的文件混合在一起才不是工作!感谢所有试图提供帮助的人!

相关内容