Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to retrieve MySQL data when the operating system is down

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to retrieve MySQL data from operating system outages". In daily operation, I believe many people have doubts about how to retrieve MySQL data when operating systems are down. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to retrieve MySQL data when operating systems are down." Next, please follow the editor to study!

I. Overview

If the Linux operating system goes down, it doesn't start, and rescue installed system doesn't work, can the MySQL data on the machine still be recovered? If so, how to recover? With this question, let's do an experiment.

II. Introduction to the environment

Prepare two virtual machines, the virtual machine software is virtualbox.

IP 192.168.56.81 the virtual machine runs MySQL, then simulates the crash of the machine, and then rescues the MySQL data.

The document on "81":

MySQL database on "81":

IP 192.168.56.71 this virtual machine is a new machine, and the database on "81" needs to be migrated to "71" later.

3. Start the experiment

Delete the / boot directory file on the "81" machine, and then force a restart.

At this time, the system fails to start, report error: file'/ grup2/i386-pc/normal.mod' not found.

Close the failed virtual machine "81" and select force exit.

Mount the hard disk of the failed virtual machine "81" to the new virtual machine "71" and start the new virtual machine "71".

Through lsblk, you can see that sdb is the newly mounted disk.

Set up the mount point and mount the new disk. Prompt mount: unknown filesystem type 'LVM2_member'

[root@oracletest ~] # mkdir / newmnt [root@oracletest ~] # mount / dev/sdb2 / newmntmount: unknown filesystem type 'LVM2_member'

This is because / dev/sdb2 is a physical volume and cannot be mounted directly. The logical volume corresponding to the physical volume needs to be mounted.

Looking at the logical volume (which may take a while to see), you can see that LV Status is NOT available.

Using vgchange-ay / dev/vg to activate the logical volume group (vg is the name of the logical volume group), you can see that LV Status is available.

Mount the logical volume and you can see that the file has been recovered.

[root@oracletest ~] # mount / dev/vg/lvroot / newmnt [root@oracletest ~] # cd / newmnt [root@oracletest newmnt] # lsbin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@oracletest newmnt] # cd / newmnt/root [root@oracletest root] # lsimportant.txt install.sh mysql-8.0.22-linux-glibc2.12-x86_ 64.tar.xz [root @ oracletest root] # cat important.txt this is important text!

Next is to restore the MySQL database. The principle is very simple, no different from migrating MySQL, that is, migrate the original MySQL file to a new directory, and then start the library.

First install the same version of MySQL on the new virtual machine "71" as in the failed virtual machine (the installation process is slightly... ).

Check the parameter file of the original MySQL and determine the directory of the MySQL log file and data file.

[root@oracletest root] # cat / newmnt/etc/my.cnf [mysqld] # basic settings #... basedir = / usr/local/mysqldatadir = / opt/mydata/datatmpdir = / opt/mydata/tmplog_bin = / opt/mydata/log/binlog/binlog...

View the data file of the original MySQL.

[root@oracletest root] # cd / newmnt/opt/mydata/ [root@oracletest mydata] # lltotal 12drwxr-xr-x 6 995 1000 4096 Feb 11 14:03 datadrwxr-xr-x 4 995 1000 4096 Feb 11 14:03 logdrwxr-xr-x 2 995 1000 4096 Feb 11 14:03 tmp

Create related directories.

Mkdir-p / opt/mydata/datamkdir-p / opt/mydata/tmpmkdir-p / opt/mydata/log/binlogchown-R mysql:mysql / opt/mydata

Copy the MySQL file to the corresponding directory.

Cp-r / newmnt/etc/my.cnf / etccp-r / newmnt/opt/mydata/data / opt/mydata/cp-r / newmnt/opt/mydata/log/binlog / opt/mydata/log/chown-R mysql:mysql / opt/mydata # the purpose of this step is because the user and group to which the original file belongs will be lost when it is hung on a new machine and needs to be changed back to the mysql group

Start MySQL.

[root@oracletest] # service mysql startStarting MySQL.2021-04-08T11:39:26.437943Z mysqld_safe error: log-error set to'/ opt/mydata/log/error.log', however file don't exists. Create writable for user 'mysql'.The server quit without updating PID file (/ opt/mydata/ data [failed] est.pid).

An error is reported, indicating that there is no error.log, then create one and start MySQL.

[root@oracletest ~] # touch / opt/mydata/log/error.log [root@oracletest ~] # chown-R mysql:mysql / opt/mydata/log/error.log [root@oracletest ~] # service mysql startStarting MySQL.. [OK]

You can see that the tables in the database have also been found!

At this point, the study on "how to retrieve MySQL data from operating system outages" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report