MySQL

Basic LAMP Performance Tuning

Linux:
(2.6 kernel only)
Check vm.swappiness: sysctl -A|grep swap
The default is 60, which is generally too high... if it is still the default, set it to 20:

sysctl -w vm.swappiness=20
echo "vm.swappiness = 20" >> /etc/sysctl.conf

Submitted by jkelly on Thu, 2007-07-05 19:14. categories [ | | | | ] read more

Optimize all tables script

for i in `mysql -B -e "show databases"|grep -v Database`; \
do for j in `mysql $i -B -e "show tables;"|grep -v Tables_`; \
do mysql $i -e "optimize table $j";done;done;

Submitted by jkelly on Wed, 2007-02-28 15:03. categories [ | ]

Deleting a MySQL User

If you're using MySQL 4.1.1 or newer, you can use the following:

DROP USER user@host;

On older versions, you'll need to use:
DELETE FROM mysql.user WHERE User='user' AND Host='host';
FLUSH PRIVILEGES;

Submitted by jkelly on Thu, 2006-08-24 04:12. categories [ | ] read more

Upgrading MySQL

This article relates to upgrading MySQL on Redhat linux, but may be applicable to other OSes as well.

Here's the short version:
* Add mysql to the up2date package skip list
* Do a full MySQL dump (mysqldump -Q -A --opt >mysqlbak.sql)
* Stop MySQL
* Upgrade MySQL from the appropriate mysql.com RPMs (including the shared-compat package)
* useradd -u 27 -d /var/lib/mysql -s /bin/bash mysql (if the user doesn't exist)
* comment out the basedir= line from /etc/my.cnf, or parse_server_arguments function call from /etc/init.d/mysql (for MySQL 5.0+)

Submitted by jkelly on Sun, 2006-08-13 08:02. categories [ | | ] read more

Changing a MySQL user's password

To set the password of an existing user, you use:

SET PASSWORD FOR 'user'@'host' = PASSWORD('newpass');

An equivalent command is:

UPDATE mysql.user SET Password=PASSWORD('newpass')
  WHERE User='user' AND Host='host';
FLUSH PRIVILEGES;

Submitted by jkelly on Sat, 2006-08-12 03:26. categories [ | ] read more

Adding MySQL Users / Setting User Privileges

The syntax for adding a user is:

mysql> GRANT [privs] ON [db] TO [user]@[host] IDENTIFIED BY [pass];

e.g.
mysql> GRANT ALL PRIVILEGES ON testdb.* TO 'bob'@'localhost' IDENTIFIED BY '3kuh3Ok';

Would grant all privileges on the testdb database to the local user bob, with password 3kuh3Ok.

Submitted by jkelly on Sat, 2006-08-12 03:22. categories [ | ] read more

MySQL Performance Tuning

Matt Mongomery at MySQL has developed a great MySQL "tuning primer" that will suggest basic performance tuning settings. It is available at: http://www.day32.com/MySQL/tuning-primer.sh

MySQL should be allowed at least 48 hours of normal operation before running, to allow for the best suggestions.

Submitted by jkelly on Thu, 2006-08-10 22:53. categories [ | ] read more
Syndicate content