> For the complete documentation index, see [llms.txt](https://docs.neevcloud.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.neevcloud.com/neevcloud-guide/neevcloud-knowledgebase/how-to-install-mysql-on-ubuntu-22.04/mysql-database-backup-and-restore-by-mysqldump.md).

# Mysql database backup and restore by mysqldump

## MySQL: The Go-To Open-Source RDBMS

**MySQL** is a premier open-source Relational Database Management System (RDBMS) acclaimed for its ability to efficiently store, manage, and retrieve structured information. It serves as the backbone for a myriad of applications, ranging from modest personal projects to complex, high-traffic internet sites and sophisticated enterprise solutions.

Key highlights of MySQL include its high performance, robust reliability, seamless scalability, and user-friendly nature. Moreover, it boasts wide compatibility across leading operating systems such as Linux, macOS, Windows, and Ubuntu, making it a versatile solution for any environment.

## **Prerequisites: -**

Require two Ubuntu 22.04

mysql-server-8.0

### Update && upgrade

```
apt-get update -y && apt-get upgrade -y 
```

### **Install MySQL**&#x20;

Install MySQL by typing the following command:

```
apt-get install mysql-server-8.0 -y
```

To secure the installation, **MySQL** inside-

<figure><img src="/files/IBP2ek32oL6DfSDwY0fb" alt=""><figcaption></figcaption></figure>

### Create **MySQL** databas*e:*

```
mysql> create database testing_database; 
```

<figure><img src="/files/PhLGnjhJ7ljO1sHKTZJ1" alt=""><figcaption></figcaption></figure>

Using testing database-

```
mysql> user tesing_database;
```

<figure><img src="/files/0kjisg5sWqICxsjhJmcd" alt=""><figcaption></figcaption></figure>

Create testing\_table in the testing\_database&#x20;

```
mysql> create table testing_table (id int, name varchar(50), address varchar(50), primary key (id));
```

<figure><img src="/files/vYCiHqKTag89aV5AlSiR" alt=""><figcaption></figcaption></figure>

Insert data to testing\_table

```
mysql> insert into testing_table(id, name, address) values("001", "Ubuntu", "Hiroshima");
```

<figure><img src="/files/NhrimBZ8ufB3aNqiIN1a" alt=""><figcaption></figcaption></figure>

show testing\_table

```
mysql> select * from testing_table;
```

<figure><img src="/files/4TC1nLOimvJA0nTwQoc5" alt=""><figcaption></figcaption></figure>

### TAKE MYSQL BACKUP AND RESTORE

```
mysqldump --lock-all-tables --all-databases --events > mysql_dump.sql
```

<figure><img src="/files/xBSGR3vhSkdGQKIxmEaS" alt=""><figcaption></figcaption></figure>

Dump all data without locking but with transaction-ensured data integrity by \[--single-transaction] option:-

<figure><img src="/files/6fLFtfvzycV8rWVU6QK9" alt=""><figcaption></figcaption></figure>

Dump specific database:-

```
mysqldump test_database --single-transaction --events > mysql_dump.sql
```

<figure><img src="/files/4XiUWIFFSN7SP509K9vX" alt=""><figcaption></figcaption></figure>

### For Restore Database

For restoring data from backup on another host, run as follows. Before restoring, transfer dump data to the target host with \[rsync] or \[scp] and so on.

Copy these mysql\_dump.sql another machine:

<figure><img src="/files/Xff6NSPpOqxnWwbfM7h1" alt=""><figcaption></figcaption></figure>

**$ sftp root\@another\_machine\_ip**

<figure><img src="/files/k7c9tYgXjfgWvfqDPdMm" alt=""><figcaption></figcaption></figure>

Go to another server machine:&#x20;

<figure><img src="/files/0D7r5YxjjXcRHdNW298Y" alt=""><figcaption></figcaption></figure>

```
apt-get install mysql-server-8.0 -y
```

<figure><img src="/files/GFTJ9XI8qf8GaGPaol19" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/DFYHJiKbvFHrDYUQsIvR" alt=""><figcaption></figcaption></figure>

```
mysql testing_database < mysql_dump.sql
```

<figure><img src="/files/XbGe714kpjrLUoNzJKsB" alt=""><figcaption></figcaption></figure>
