Archive

Archive for the ‘MySQL’ Category

Enable MySQL Query Log File

October 26th, 2008 1 comment

MySQL has built-in functionality that allows you to log SQL queries to a file , You can enable the full SQL queries logs to a file or only slow running queries log.  It is easy for us to troubleshoot/ debug the sql statement if SQL queries log enable , The slow query log  is  used to find queries that take a long time to execute and are therefore candidates for optimization.

To enable you just need to add some lines to your my.cnf file, and restart. Add the following:

  • To enable slow Query Log only

log-slow-queries = /var/log/mysql/mysql-slow.log
long_query_time = 1

After enabling slow query, mysqld writes a statement to the slow query log file and it consists of all SQL statements that took more than long_query_time seconds to execute. The time to acquire the initial table locks is not counted as execution time. mysqld only log after SQL statements has been executed and after all locks have been released, so log order might be different from execution order. The minimum and default values of long_query_time are 1 and 10, respectively.

  • To enable full Log Query

log=/var/log/mysqldquery.log

The above will log all queries to the log file.

Note :: Don’t forgot to restart mysql service after making changes in my.cnf file.

Regards

How do you repair a corrupt MySQL table?

October 23rd, 2008 No comments

Hello,

Error: Table ‘tbl_ name’ doesn’t exist databasename_tablesname.frm can’t open

If you get either of the following errors, it usually means that no table exists in the current database with the given name:

Table ‘tbl_name’ doesn’t exist

Can’t find file: ‘tbl_name’ (errno: 2)

A ) In some cases, it may be that the table does exist but that you are referring to it incorrectly:

Because MySQL uses directories and files to store databases and tables, database and table names are case sensitive if they are located on a file system that has case-sensitive filenames.

Even for file systems that are not case sensitive, such as on Windows, all references to a given table within a query must use the same letter case.

B ) In some cases, it may be that the table exist but same error occurs then

1 ) Check the permission and ownership of database i.e. it should be same below

drwx—— 2 mysql mysql cpanelusername_dbname.

2) If the permission are corrects but same error occurs then it seems that your database table may be corrupts then there are following way to repair the DB

a) Go to whm >>SQL Services >> Repair a Database >> select database name and click Repair Database.

b) Go to cpanel >> mysql section MySQL Account Maintenance >> search database then click on Repair.

C) You can repair it though shell when mysqld server is running

i) login in mysql to that particular user by using following command

mysql>mysql –u databaseusername –p databasename

ii) select particular database

mysql> use databasename;

iii) Check whether database table is corrupted or not if following command output shows null value then it should be corrupts otherwise it is fine

mysql>show table status like ‘table name’\G; Or
mysql>check table tablename ;

iv)If it is corrupts then use the following command to repair that particular database table.

mysql>repair table tablename;

D] You can repair it though shell when mysqld server is not running

Repairing MyISAM mySQL Tables/Databases:

# cd /var/lib/mysql/DBNAME

# myisamchk tablename.MYI

Repairing ISAM mySQL Tables/Databases:

# cd /var/lib/mysql/DBNAME
isamchk tablename.MYI
where

-c –> check database is corrupted or not
-r –> recorver
-o –> optimise the database

Enjoy…………………………..:D