Cool Dba

  • Home
  • Sql tricks
  • Security
  • Maintainance
  • Backups
  • Recovery
  • Replication
  • Installation
  • Linux
Showing posts with label Recovery. Show all posts
Showing posts with label Recovery. Show all posts

Tuesday, May 24, 2016

Check and Repair Mysql Tables

 Anil Joshi     12:13 AM     Database Maintainance, Recovery     No comments   



 Check a Specific Table in a Database

If your application throws an error message saying that a specific table is corrupted, execute the mysqlcheck command to check it.
The following example checks t1 table in test database.
# mysqlcheck -c test t1 -u root -p
Enter password:
test.t1    OK


Kindly Note, that myisamchk command  works similar to the mysqlcheck command. The advantage of mysqlcheck command is that it can be executed when the mysql daemon is running. So, using mysqlcheck command you can check and repair corrupted table while the database is still running.

Check All Tables in a Database

To check all the tables in a particular database follow this
The following example checks all the tables in the test database.
# mysqlcheck -c test  -u root -p
Enter password:
test.t1                            OK
test.t2                            Ok


Check All Tables and All Databases
To check all the tables and all the databases use the “–all-databases” along with -c option as shown below.
# mysqlcheck -c  -u root -p --all-databases
Enter password:
test.employee                              OK
live.JBPM_ACTION                           OK
dev.emp
error    : Table emp required. Please do "REPAIR TABLE `emp`" or dump/reload to fix it!


Check all tables of few databases
# mysqlcheck -c  -u root -p --databases test live
Enter password:
test.employee                              OK
live.student                               OK

 Analyze Tables using Mysqlcheck

# mysqlcheck -a test t1 -u root -p
Enter password:
test.t1   Table is already up to date

Internally mysqlcheck command uses “ANALYZE TABLE” command. While mysqlcheck is executing the analyze command the table is locked and available for other process only in the read mode

Optimize Tables using Mysqlcheck

# mysqlcheck -o test t1 -u root -p
Enter password:
test.t1         OK

Internally mysqlcheck command uses “OPTIMIZE TABLE” command. When you delete lot of rows from a table, optimizing it helps to get the unused space and defragment the data file. This might improve performance on huge tables that has gone through several updates.

Repair Tables using Mysqlcheck

# mysqlcheck -r test t1 -u root -p
Enter password:
test.t1        OK
Internally mysqlcheck command uses “REPAIR TABLE” command. This will repair and fix a corrupted MyISAM and archive tables.
Combine Check, Optimize, and Repair Tables
Instead of checking and repairing separately. You can combine check, optimize and repair functionality together using “–auto-repair” as shown below.
# mysqlcheck -u root -p --auto-repair -c -o test
You an also check, optimize and repair all the tables across all your databases using the following command.
# mysqlcheck -u root -p --auto-repair -c -o --all-databases
 add the –debug-info as shown below for getting more information
# mysqlcheck --debug-info -u root -p --auto-repair -c -o test t1
Enter password:
test.t1  Table is already up to date
 User time 0.00, System time 0.00
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 344, Physical pagefaults 0, Swaps 0

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Friday, May 20, 2016

Recovering InnoDB MySQL Tables Data from ibdata and .frm Files

 Anil Joshi     3:35 AM     Recovery     No comments   


First Check Error Logs.

InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting

The method explained below will work only for InnoDB database.
Note: First take a backup of all the MySQL files and database.
Contents Of Mysql Data Directory.
drwx------ 2 mysql mysql     4096 Oct 11  2012 performance_schema
drwx------ 2 mysql mysql     4096 Dec 10  2012 ndbinfo
drwx--x--x 2 mysql mysql     4096 Dec 10  2012 mysql
-rw-rw---- 1 mysql mysql       56 Dec 19  2012 auto.cnf
drwx------ 2 mysql mysql     4096 Jul 30  2013 bugs
-rw-r----- 1 mysql mysql 50331648 Mar 18 10:35 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Apr 22  2013 ib_logfile1
-rw-r----- 1 mysql mysql 35651584 Mar 18 10:35 ibdata1
..

§  Ibdata1 – This file is the InnoDB system table space, which contains multiple InnoDB tables and associated indexes.
§  *.frm – Holds metadata information for all MySQL tables. These files are located inside the folder of the corresponding MySQL database. (for example, inside “bugs” directory)
§  ib_logfile* – All data changes are written into these log files. This is similar to the archive logs concepts that we find in other RDBMS databases.
Copy the Files
 First stop the MySQL server.
# service mysqld stop
Copy the ibdata files, and the database schema folder to some other directory. We will use this to restore our Mysql database. In this case, we’ll copy it to the /tmp directory. The name of the database scheme in this example is Sakila.
cp –r ibdata* ib_logfile* /tmp

cp –r schema_name/  /tmp/schema_name/
Start the MySQL server:
# service mysqld start

Restore the Data

In the my.cnf configuration file, set the value of the following parameter to the current size of the ib_logfile0 file. In the following example, I’ve set it to 48M, as that is the size I see for the ib_logfile0 file when I did “ls -lh ib_logfile0″
innodb_log_file_size=48M
Please note that both the ib_logfile0 and ib_logfile1 file size will be the same.
Copy the previous ibdata files to respective position, inside mysql data directory.
cp –r /tmp/ibdata* /var/lib/mysql/
Create an empty folder inside data directory with the same name as the database schema name that you are trying to restore, and copy the previous .frm files inside this folder as shown below:
cp –r /tmp/ib_logfile* /var/lib/mysql/
cp –r /tmp/schema_name/*.frm /var/lib/mysql/schema_name/
Finally we done,restart the MySQL server.

service mysqld restart
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Older Posts Home

Deals on Amazon

Mobiles on Amazon

About Me

My photo
Anil Joshi
New Delhi, Delhi, India
I am a simple man with little knowledge of computer software and Tehnology.
View my complete profile

Popular Posts

  • SELinux mechanism in linux environment.
    Security-Enhanced Linux (SELinux) is a mandatory access control (MAC) security mechanism implemented in the kernel. SELinux was first ...
  • Dual Master Replication(Master-Master)
    MySQL replication is the most flexible way to deal with scalability and availability. The most common problem with replication is ...
  • Filter Replication Variables
    Filtering can be done on the Master or on the Slave. Filtering on the Slave is normally preferred as in this case you get full binary lo...
  • Complete uninstallation of Mysql Server on centos
    Step 1: Check list the mysql rpm which is installed on server rpm -qa | grep mysql or yum list installed | grep mysql Step 2 : Re...
  • Master-Slave Replication without downtime
    First, we configure master’s   /etc/mysql/my.cnf   by including these lines in the [mysqld] section: server - id = 1 bin...
  • Tracing the execution of processes using strace
    Strace is quite simply a tool that traces the execution of system calls. It can trace the execution of a binary from start to end, and ou...
  • Mysql Installation using rpm package
        1.Download the required rpm filess MySQL-client-community-5.1.25-0.rhel5.i386.rpm MySQL-server-community-5.1.25-0.rhel5.i386....
  • Finding and preventing ddos attack on Linux Server
    A distributed denial-of-service (DDoS) attack occurs when multiple systems flood the bandwidth or resources of a targeted system, usual...
  • MySQL Restart Failed
           MySQL Restart Failed :   The Server Quit Without Updating PID File [root@server: ~ ] $ service mysqld start Starti...
  • Mysql Security
    Improved  MySQL Database Se curity 1. Secure your server Many known attacks are possible only once physical access to a machi...
Best Shoes on amazon

Categories

  • Backups
  • Database Maintainance
  • Installation
  • Linux
  • Mysql
  • Recovery
  • Replication
  • Scripts
  • Security
  • SELinux
  • sql tricks
  • Strace

Pages

  • Home

Blog Archive

  • ▼  2016 (19)
    • ▼  June (1)
      • Complete uninstallation of Mysql Server on centos
    • ►  May (18)

Sample Text

Copyright © Cool Dba | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates