MySQL Configuration

The previous article on the LAMP Server enables you to get started but you will need to do some configuration with MySQL before you go to far. This article and the next several articles will help you create a database and learn how to monitor it as well as backup and restore.

The MySQL server provides the database that will be connected with PHP and Apache. Installation is easily done with apt-get.

sudo apt-get install mysql-server

During the process you will be asked to create a password for the root user for MySQL. Note this is not the root user for the Linux system and the accounts should have different passwords. Be sure to write down the password. When the installation program completes, you can use the netstat utility to verify that MySQL is running correctly:

sudo netstat -tap | grep mysql

tcp 0 0 localhost:mysql *:* LISTEN 844/mysqld

Here, you can see that MySQL is active, and is listening on port 844.

Note that you don’t have to use the “sudo” command with MySQL server, even though we’re logged on with the user account instead of the root account.

You can add a password to both the server account and the mysql root account at the same time if for some reason your MySQL server did not get a password set.

mysqladmin -h localhost -u root password “the_password_you_want”

Now, if you try to log on to MySQL without the password, you’ll get this:

Also for security’s sake, you’ll want MySQL to run with a non-privileged user account, instead of as root. For that, you can use the user and group named “mysql”. As luck would have it, the Ubuntu Server installation of MySQL has already taken care of this for you. (Of course, you would still log on to MySQL as “root” instead of as “mysql”.)

There is one other thing you might want to do, though, to keep the riff-raff out of your data directory. That is, take away the “group” and “other” permissions.

sudo chmod -R go-rwx /var/lib/mysql

If you are interested in a Live Course for Ubuntu 9.10 we provide that option as well. Otherwise, we hope you find this Free mini-course useful which we will roll out over a number of days..