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 182010
 

Put a profile in AppArmor complain mode

Answer:

Some applications, such as the MySQL server, if you changed the default datadir, you might not be able to startup MySQL.

To solve the problem, put the MySQL profile in AppArmor complain mode can solve the problem.

# sudo aa-complain /usr/sbin/mysqld

Then reload AppArmor

# sudo invoke-rc.d apparmor reload