Overview

MySQL is a relational database or RDBMS that is quite popular with the Open Source crowd and increasingly popular with companies that are trying to save some money and/or gain some flexibility with their database servers.

This page contains tips and tricks for using MySQL. The best place to start, however, is the MySQL Reference Manual (v5.1). I also like the JOIN-FU site for articles about SQL.

Performance Tuning

A good starting point for performance tuning is to read the MySQL documentation sections on optimization and storage engines. Also, look at replication, clustering, and partitioning if they apply.

This Performance Tuning Best Practices video and PDF presentation cover some interesting points as well.

Add a User

One easy way to add a new user to a MySQL database is to copy an existing user that has similar permissions as the one you are creating. The following code does this:

echo "use mysql; create table t select * from user where User = 'root';
  update t set User = 'username', Password = PASSWORD('password');
  insert user select * from t; flush privileges; drop table t" | mysql -p

In this case user username is created with password having the same database privileges as the root user. Note: It is assumed that a table t does not exist in the database.