Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Apr 182010
 

Repair table in MySQL

Answer:

If you are using the MyISAM storage engine, database might be corrupted when the computer was shutdown unexpectedly. To repair the table, you can use the following command in the MySQL client.

mysql> REPAIR TABLE my_table;

Feb 252010
 

Change MySQL replication master host

Answer:

To change the MySQL replication master host from a MySQL slave, follow the steps below.

1. Copy current master bin log file name and position

mysql> STOP SLAVE;
mysql> SHOW SLAVE STATUS\G

You will find something like the following...

Master_Log_File: mysql-bin.000081
Read_Master_Log_Pos: 3684056824

2. Change to new master using command

mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.2', MASTER_LOG_FILE='mysql-bin.000081', MASTER_LOG_POS=3684056824;
mysql> START SLAVE;

Feb 242010
 

Flush all MySQL log files

Answer:

MySQL default has several log files such as the error log, query log, and slow query log.

Sometimes, To perform log rotation, it is necessary to tell MySQL stop writing to these old log files, rename it and start over again.

To do so, you can execute the FLUSH LOG command in the MySQL client.

mysql> FLUSH LOG;

As a result, it will causes the MySQL to rename the current error log file with a suffix of -old and create a new empty log file.

Usually you should no need to do it manually, you should use tool such as logrotate .

Reference: http://dev.mysql.com/doc/refman/5.0/en/flush.html

Feb 142010
 

Turn off InnoDB support in MySQL

Answer:

If you never use the InnoDB storage engine in MySQL, it is better to disable it.

To disable this feature, edit the MySQL configurations, e.g. /etc/my.cnf

[mysqld]
...
...
skip-innodb

Add the "skip-innodb" will do the tricks for you.

Don't forget to restart MySQL to take effect.

# /sbin/service mysqld restart