Arxiv

Archive for İ

Copying Tablespaces to Another Server (Transportable Tablespaces)

May 17, 2014 2 şərh

Bugünkü mövzumuz MySQL 5.6 > versiyalar nəzərdə tutulub odur ki, test etməzdən əvvəl mütləq əmin olun ki, sizin MySQL versiyanlz müvafiqdir.
İndiki hald mən 5.6.17 versiya MySQL-i aşağıdakı opsiyalarla start etmişəm.
QEYD: Transportable Tablespaces-ə nail olmağınız üçün MySQL-i aşağıdakı dəyişənlərlə start etməlisiniz

[mysqld]
innodb_file_per_table          = 1
lower_case_table_names         = 1

Daha sonra test məqsədi ilə, bir kifayət qədər böyük cədvəl tapın.
Məndə artıq biri var təqribən 2.4 gb-dır.
O cədvəli rename edək:

[root@linuxsrv3 xxx]# ls -lthr
total 2,4G
-rw-rw----. 1 mysql mysql   65 2014-05-07 11:05 db.opt
-rw-rw----. 1 mysql mysql  20K 2014-05-12 12:07 test_table.frm
-rw-rw----. 1 mysql mysql 2,4G 2014-05-12 14:05 test_table.ibd

Cədvəlimizi test_table-dan test_table2-yə rename edək.:

[root@linuxsrv3 xxx]# time mysql -u root -p -e 'rename table xxx.test_table to xxx.test_table2'
Enter password: 

real	0m1.973s
user	0m0.002s
sys	0m0.004s

Bu cəmi 1.9 saniyə çəkdi.

Rename-in başqa istifadə yeri də var. Deyək ki, biz bir database-dən cədvəli digərinə move etmək istəyirik bu zaman cədvəlin backup-ını alıb, digər database-də import etməyə ehtiyac yoxdur, aşağıdakı şəkildə bunu edə bilərik:

[root@linuxsrv3 xxx]# time mysql -u root -p -e 'rename table xxx.test_table2 to test.test_table2'
Enter password: 

real	0m1.876s
user	0m0.005s
sys	0m0.003s

Və bizim cədvəlimiz artıq, test database-indədir:

[root@linuxsrv3 test]# ls -lthr
total 2,4G
-rw-rw----. 1 mysql mysql 8,4K 2014-05-12 11:32 ff.frm
-rw-rw----. 1 mysql mysql  96K 2014-05-12 11:33 ff.ibd
-rw-rw----. 1 mysql mysql   65 2014-05-12 11:34 db.opt
-rw-rw----. 1 mysql mysql  20K 2014-05-12 12:07 test_table2.frm
-rw-rw----. 1 mysql mysql 2,4G 2014-05-12 14:05 test_table2.ibd

Deməli gördüyünüz kimi, bir cədvəli bir database-dən digərinə move etməyin sürətli və asan yolunu göstərmiş olduq.
Lakin belə bir sual yaranır, bəs biz bir cədvəli digər server-dəki database-ə copy edə bilərik mi?
Transportable Tablespaces məhz burda bizim köməyimizə gəlir.
Bir daha xatırlatmaqda fayda var ki, buna nail olmanız üçün my.cnf faylında yazının əvvəlində göstərdiyim kimi, dəyişənləri qeyd edib, MySQL-i start etmək lazımdır.
Həmçinin, sizin remote server-də artıq eyni adlı database və eyni adlı (strukturlu) cədvəliniz olmalıdır.

Bizim serverlər aşağıdakılardır:

source server : linuxsrv3
Destination server : linuxsrv4

Destination server-də artıq eyni adlı database və cədvəlimiz var.

Destination server-də biz mövcud boş cədvəlimizin tablespace-ini discard edirik:

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> alter table test_table2 discard tablespace;
Query OK, 0 rows affected (0,05 sec)

Əgər yoxlasanız görərsiniz ki, .ibd faylı databse direktoriyamızda yoxdur.

[root@linuxsrv4 test]# ls
db.opt  test_table2.frm

Source serverimizdə:

mysql> use test;
Database changed
mysql> FLUSH TABLES test_table2 FOR EXPORT;
Query OK, 0 rows affected (0,00 sec)

.ibd faylını destination server-ə copy edirik:

[root@linuxsrv3 test]# scp test_table2.ibd root@192.168.1.88:/var/lib/mysql/test
root@192.168.1.88's password: 
test_table2.ibd                       100% 2444MB  15.4MB/s   02:39 

Source server-də:

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

mysql> UNLOCK TABLES;
Query OK, 0 rows affected (0,00 sec)

destination server-də:

[root@linuxsrv4 test]# ls
db.opt  test_table2.frm  test_table2.ibd

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> alter table test_table2 IMPORT TABLESPACE;
ERROR 1146 (42S02): Table 'test.test_table2' doesn't exist

Əgər bu error-u gördünüzsə demək ki, owner:

[root@linuxsrv4 test]# ls -l
total 2502684
-rw-rw----. 1 mysql mysql         65 2014-05-12 15:03 db.opt
-rw-rw----. 1 mysql mysql      20166 2014-05-12 15:05 test_table2.frm
-rw-r-----. 1 root  root  2562719744 2014-05-12 15:16 test_table2.ibd

Owner-i mysql user-ə dəyişək:

[root@linuxsrv4 test]# chown mysql:mysql test_table2.ibd
[root@linuxsrv4 test]# ls -l
total 2502684
-rw-rw----. 1 mysql mysql         65 2014-05-12 15:03 db.opt
-rw-rw----. 1 mysql mysql      20166 2014-05-12 15:05 test_table2.frm
-rw-r-----. 1 mysql mysql 2562719744 2014-05-12 15:16 test_table2.ibd

İndi isə bir daha sınayaq:

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

mysql> alter table test_table2 IMPORT TABLESPACE;
Query OK, 0 rows affected, 1 warning (2 min 29,38 sec)

And checking :

mysql> select idvisit from test_table2 order by idvisit desc limit 1;
+---------+
| idvisit |
+---------+
| 7016951 |
+---------+
1 row in set (0,04 sec)

Bununla da gördüyünüz kimi 2.4 gb-lik bizim cədvəl artıq başqa bir server-də eyni data-larla mövcuddur. Bu əməliyyat toplamda 2 dəqiqə çəkir.
Təşəkkürlər.