MySQL Commands
6th January 2006 - By Aaron
Here is a list of some of the MySQL commands I have had to either look up or have handy for server admin.
Start MySQL - /etc/rc.d/init.d/mysqld start
Stop MySQL - /etc/rc.d/init.d/mysqld stop
Restart MySQL - /etc/rc.d/init.d/mysqld restart
If it won’t stop successfully, you can always killall mysqld.
If you killall it though, you may need to remove the lock file to rerun it.
You can do that by running rm /var/lock/subsys/mysql.
Setup MySQL to run on boot.
First check the runlevels it starts on using /sbin/chkconfig --list mysqld.
Then, if 3, 4, and 5 are not on, change them with /sbin/chkconfig --level 345 mysqld on.
To view the last 10 lines of the mysql log file, use tail /var/log/mysqld.log.
To view the last 500 lines, use tail -n 500 /var/log/mysqld.log
To delete duplicate records in MySQL, use the following code
CREATE TEMPORARY TABLE table_name_temp AS SELECT DISTINCT field FROM table_name;
DELETE FROM table_name;
INSERT INTO table_name(field) SELECT field FROM table_name_temp;