mysqldump 사용 시 <, > 꺽쇠 방향에 주의한다.
Export
OS : CentOS(4.8)
DB : MySQL(4.1.22)
Import
OS : CentOS(8.3)
DB : MariaDB(10.5.8)
# [mysql path] mysqldump -u [사용자 아이디] -p [백업할 DB명] > [생성할 파일명].sql
ex) # mysqldump -u root -p ExportDB > export_backup_db.sql
# /usr/local/mysql/bin/mysqldump -u root -p ExportDB > export_backup_db.sql
# ls -la | grep export_backup_db.sql
-rw-r--r-- 1 root root 0 Jan 20 08:09 export_backup_db.sql
# vi export_backup_db.sql
-- MySQL dump 10.9
--
-- Host: localhost Database: ExportDB
-- ------------------------------------------------------
-- Server version 4.1.22
...
DROP TABLE IF EXISTS `test_table`;
CREATE TABLE `test_table` (
`uid` int(11) unsigned NOT NULL auto_increment,
`test_code` varchar(30) default NULL,
`test_access` int(11) NOT NULL default '0',
...
# ls -la | grep export_backup_db.sql
-rw-r--r--. 1 root root 209423808 Jan 20 08:21 export_backup_db.sql
# mysql -u root -p
# CREATE DATABASE [DB명];
# exit
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.5.8-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE IMPORT_DB;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> exit
Bye
# ls -la | grep IMPORT_DB
drwx------. 2 mysql mysql 20 Jan 20 08:25 IMPORT_DB
# mysql -u root -p [import할 DB명] < [백업했던 파일명].sql
# mysql -u root -p IMPORT_DB < export_backup_db.sql
mysql> select uid, test_left, test_top, test_height, test_width from test_table;
+-----+------------+-----------+--------------+-------------+
| uid | test_left | test_top | test_height | test_width |
+-----+------------+-----------+--------------+-------------+
| 2 | 350 | 110 | 240 | 400 |
| 3 | 360 | 100 | 306 | 420 |
| 4 | 360 | 100 | 357 | 424
....
+-----+------------+-----------+--------------+-------------+
9 rows in set (0.00 sec)
MariaDB [IMPORT_DB]> select uid, test_left, test_top, test_height, test_width from test_table;
+-----+------------+-----------+--------------+-------------+
| uid | test_left | test_top | test_height | test_width |
+-----+------------+-----------+--------------+-------------+
| 2 | 350 | 110 | 240 | 400 |
| 3 | 360 | 100 | 306 | 420 |
| 4 | 360 | 100 | 357 | 424 ....
+-----+------------+-----------+--------------+-------------+
9 rows in set (0.000 sec)