我拥有一个运行 raspbian jessie (SYS_A) 的树莓派 1。两周前我执行了系统更新(aptitude update && aptitude upgrade,不是 aptitude dist-upgrade,因为我知道它存在 raspbian stretch)并且出现了一个不希望的情况。
我正在运行一个 MySQL 数据库,我猜是 5.5 版。升级后systemd没有启动mysqld守护进程,其日志如下:
user@rpi:~ $ sudo systemctl start mysql
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
user@rpi:~ $ systemctl status mysql.service
● mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql)
Active: failed (Result: exit-code) since mar 2017-10-10 10:13:11 CEST; 55s ago
Process: 7815 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)
user@rpi:~ $ sudo systemctl status mysql.service
● mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql)
Active: failed (Result: exit-code) since mar 2017-10-10 10:13:11 CEST; 2min 46s ago
Process: 7815 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)
oct 10 10:13:10 rpi /etc/init.d/mysql[8535]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
oct 10 10:13:11 rpi mysql[7815]: Starting MySQL database server: mysqld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . failed!
oct 10 10:13:11 rpi systemd[1]: mysql.service: control process exited, code=exited status=1
oct 10 10:13:11 rpi systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
oct 10 10:13:11 rpi systemd[1]: Unit mysql.service entered failed state.
幸运的是,我没有删除里面的 MySQL 文件/var/lib/mysql
,所以看起来所有的数据都保留在那里。
我试图打开ibdataX
文件,但似乎是二进制文件...
我还尝试过在另一个树莓派中设置另一个 raspbian jessie (SYS_B),安装 mysql,停止服务,备份 SYS_B 的原始/var/lib/mysql
文件夹,将其替换为 SYS_A 的/var/lib/mysql
文件夹,然后再次启动 mysqld 守护进程。但这导致了与 SYS_A 中相同的启动错误。
我有一个 wordpress 数据库,我不想丢失它。那么,有什么办法可以恢复吗?
/var/logs/mysql/error.log
171010 10:12:36 [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.
171010 10:12:36 [Note] Plugin 'FEDERATED' is disabled.
171010 10:12:36 InnoDB: The InnoDB memory heap is disabled
171010 10:12:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
171010 10:12:36 InnoDB: Compressed tables use zlib 1.2.8
171010 10:12:36 InnoDB: Using Linux native AIO
171010 10:12:36 InnoDB: Initializing buffer pool, size = 128.0M
171010 10:12:37 InnoDB: Completed initialization of buffer pool
171010 10:12:37 InnoDB: highest supported file format is Barracuda.
171010 10:12:38 InnoDB: Waiting for the background threads to start
171010 10:12:39 InnoDB: 5.5.57 started; log sequence number 28689772
171010 10:12:39 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
171010 10:12:39 [Note] - '0.0.0.0' resolves to '0.0.0.0';
171010 10:12:39 [Note] Server socket created on IP: '0.0.0.0'.
171010 10:12:39 [ERROR] Fatal error: Can't open and lock privilege tables: Incorrect file format 'user'
总结:我无法启动 mysqld,所以我无法备份我的数据库,我不想丢失它们,尤其是与 wordpress 相关的。/var/lib/mysql 上的数据,ibd 文件等等我都没有删除。我可以将 mysql 数据库恢复到另一个安装的 mysql 中吗?
正如OP所提供的:
如此处所述,继续的方法是在安全模式下启动 mysql 守护程序,如下所示:
$ sudo mysqld_safe --user=root --skip-grant-tables
我的猜测是数据库系统在最新更新后出现故障(可能是不安全的关机、重启等……)。至于现在,我的MySQL数据库将放在NAS上,因为MySQL不会在那里更新。我还将安排备份任务。