Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 January MySQL: Check, Optimize and Repair Tables using Mysqlcheck

MySQL: Check, Optimize and Repair Tables using Mysqlcheck

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

Recently, our MySQL MyISAM table corrupted due to certain reason.

Using mysqlcheck command, we can optimize, repair and analyse the tables. (For MyISAM Engine)

First, check a specific table:
You can execute this command by giving DatabaseName and Table name.

1
2
3
mysql> mysqlcheck -c TestDB TestTable -u root -p
Enter Password:****
testdb.testtable OK

Check all the tables of a Database:
Using below command, you can also check all the tables of a Database.

1
2
3
4
5
6
mysql> mysqlcheck -c TestDB -u root -p
Enter password:****
testdb.tbl_first OK
testdb.tbl_sec OK
testdb.tbl_third OK
testdb.testtable OK

Check all the tables of a multiple Database:

1
2
3
4
5
6
mysql> mysqlcheck -c -u root -p --databases testdb mydb
Enter password:****
testdb.tbl_first OK
testdb.tbl_sec OK
testdb.tbl_third OK
mydb.tbl_first OK

Check all the tables of all databases:

1
mysql> mysqlcheck -c -u root -p --all-databases

Analyze specific table of a Database:
When you execute ANALYZE, it lock the whole table and you can access the table only for read purpose.

1
2
3
mysql>mysqlcheck -a dbname tablename -u root -p
Enter password:****
dbname.tablename OK

Optimize specific table of a Database:
When you perform bulk deletion from table, OPTIMIZE will recover all unused spaces which generated by deletion.

1
2
3
mysql>mysqlcheck -o dbname tablename -u root -p
Enter password:****
dbname.tablename OK

Repair specific table of a Database:
Below command repairs a corrupted MyISAM table.

1
2
3
mysql>mysqlcheck -r dbname tablename -u root -p
Enter password:****
dbname.tablename OK

Jan 12, 2016Anvesh Patel
MySQL: ERROR 1130: Host is not allowed to connect to this MySQL serverSQL Server: Error 262 SHOWPLAN permission denied in database
Comments: 2
  1. PISEY
    January 13, 2016 at 1:56 am

    thanks q for your posting, but this is will work successfully with Engine MyISAM. for me i am using mysql with ndbcluster engine and then i tried to follow your post but i got error:
    note : The storage engine for the table doesn’t support check

    • Anvesh Patel
      Anvesh Patel
      January 14, 2016 at 9:12 am

      Thanks for this input, True this help is only for MyISAM. I am going to update this post.
      If you want this maintenance command with InnoDB or NDB, you can use this command: ANALYZE TABLE tbl_MyTable, OPTIMIZE TABLE tbl_MyTable.

Anvesh Patel
Anvesh Patel

Database Engineer

January 12, 2016 MySQLAnvesh Patel, database, database research and development, dbrnd, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....