Mysql not start under the circumstances, how to recover data?

This article is for, mysql not start, but the data files are not lost situation.

Mysql due to unforeseen circumstances, leading to not start the case without making a backup of the database, how to migrate data to other databases.

The original database address: 192.168.1.100 (hereinafter referred to as A server)

New database address: 192.168.2.100 (hereinafter referred to as server B)

Data recovery process:

  1. A server enter, enter the command CAT /etc/my.cnf (such as the file is not in the current position, using find / -name my.cnf file location query command)

Find datadir path

  • By cd / www / server / data command to enter the data folder.

Which is the current folder mysql in all the libraries of the data files.

Below bus folder files demonstrate how to restore specific files.

  • B into the server, the server creates A bus libraries, user name, password is the same library. Once created, by the above method, the data file into the directory, there will be a bus folder.

  • Stop B mysql service server, the server bus A folder, other files except the file db.opt package, the server transmits to the bus B data directory file folder. Decompression.

  • Through the command line, the / www / server / data / bus owner and group folders, change into mysql

Change owner

Chown -R mysql /www/server/data/bus

Change Group

Chgrp -R mysql /www/server/data/bus

  • After a successful change, start the database server B, into the database, such as prompt error: 1146: Table does not exist , needs to be A server data folder ibdata1 file, copy it to the appropriate server location B, while the corresponding change all person and group permissions.

So far, the data file to restore the database is complete,

注1:如未改动数据文件夹所有者和组,启动数据库后,进入bus库点击相应表名会出现 ERROR #1017 :Can't find file: '/xxx.frm' 错误或ERROR #1036 Table '表名' is read only

注2:如数据库较多,可能会发现,部分数据库文件中有.frm .MYD .MYI这三种文件,部分数据库中只有.frm文件,这是因为MySQL存储表的时候,使用的默认数据库存储引擎是InnoDB,而使用InnoDB存储引擎的时候,是不生成.MYD 和.MYI文件的。

Guess you like

Origin www.cnblogs.com/35youth/p/11315063.html