Chapter 15. Database server (MySQL)

Some of my users want to use MySQL in their web pages. Who am I to say no to this very reasonable request.

15.1. Installing MySQL

As with the PostgreSQL database, and everything else, we need to install some packages:


apt-get install mysql-server
apt-get install mysql-doc
apt-get install php4-mysql
apt-get install libdbd-mysql-perl
apt-get install webmin-mysql

And we should now have installed the MySQL server, interfaces to Perl and PHP4 and the WebMin module for MySQL.

15.2. Configuring MySQL

In it's default install, an anonymous user is able to do some tremendous damage to the database. This is not really a Good Thing (tm), and we want to change this.

To do this, we want to disable almost anything permitted at this time, and to assign new permissions. This is easiest done in WebMin.


Go to Servers->MySQL Database Server->User Permissions
Drop all permissions from the user "Anonymous"
Set a password for the user "root"

Webmin will now throw up a DBI error, which is OK, since we just password protected the root user. Log in as root in the database, and that should be it.

When assigning databases to a user, You just need to do the following:

If we want to make things easier for local users, we can create the file .my.cnf in the users home directory. This file should contain logon information for the database, and should at the most have the permissions 0600 (-rw-------). The file should look like this:


[client]
host = localhost
user = <mysql-user>
password = <mysql-password>
database = <mysql-database>