"Enter"a basıp içeriğe geçin

MySQL DB Backup / Restore / Repair İşlemleri

Aşağıdaki komut ile belirtilen databasein dump halinin yedeği dışarı aktarılmaktadır.

mysqldump -u [user] -p [database_name] > [filename].sql

Yedeği alınan database dump dosyasi ise aşağıdaki şekilde hedef makine üzerinde bulunan db üzerine dönülmektedir.

mysql -u [user] -p [database_name] < [filename].sql

DB yedeği/dump dosyası alınırken kimi zamanlarda bazı tablolarda sorun olduğu için yedek alma işleminin hata verdiğini görebiliriz. Hatta bir tabloda sorun olması mevcut çalışan yapımızın çalışmamasına, lock olmasına ve DB bağlantı hatalarının oluşmasına neden olabilmektedir.

mysqldump -u root -p DB_xxx> /root/Desktop/rxx.sql
Enter password:
mysqldump: Got error: 145: Table './DB_xxx/xxx_options' is marked as crashed and should be repaired when using LOCK TABLES

İlgili hata alındıysa, DB sunucumuza bağlanıp mysql arayüzüne hızlıca giriş sağlayalım. Hata aldığımız database erişimini gerçekleştirelim ve REPAIR TABLE komutu ile hata alınan tablo bilgisini yazıp işlemin tamamlanmasını bekleyelim. İşlem sonrasında dump dosyasının çıktısını tekrardan almaya çalıştığımızda işlemin başarılı olduğunu görebiliriz. Hatta DB bağlantı hatası aldığımız sayfamızda erişime açılmış olacaktır.

mysql -u root -p
use dbname;
REPAIR TABLE xxx_options;
XXX~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2346
Server version: 5.5.62 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use DB_xxx;
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> REPAIR TABLE str_options;
+------------------------+--------+----------+-------------------------------------------------------------+
| Table                  | Op     | Msg_type | Msg_text                                                    |
+------------------------+--------+----------+-------------------------------------------------------------+
| DB_xxx.str_options | repair | info     | Wrong block with wrong total length starting at 187504      |
| DB_xxx.str_options | repair | info     | Wrong bytesec:  56- 50- 10 at 1815012; Skipped              |
| DB_xxx.str_options | repair | info     | Found block with too small length at 194972; Skipped        |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 196144         |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 196432         |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 196480         |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 196552         |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 196624         |
| DB_xxx.str_options | repair | info     | Found block with too small length at 981156; Skipped        |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 1067328        |
| DB_xxx.str_options | repair | info     | Wrong block with wrong total length starting at 1925804     |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 1925888        |
| DB_xxx.str_options | repair | info     | Wrong block with wrong total length starting at 1928928     |
| DB_xxx.str_options | repair | info     | Found block that points outside data file at 2048892        |
| DB_xxx.str_options | repair | warning  | Duplicate key for record at 1069008 against record at 40584 |
| DB_xxx.str_options | repair | warning  | Number of rows changed from 2162 to 2180                    |
| DB_xxx.str_options | repair | status   | OK                                                          |
+------------------------+--------+----------+-------------------------------------------------------------+
17 rows in set (2.59 sec)
Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir