Configuring MySQL on Slackware

Published: {ts '2011-02-26 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/configuring-mysql-on-slackware/

While Slackware comes with MySQL preinstalled it is not also preconfigured. There are a few critical steps you need to do to configure MySQL otherwise whenever you start Slackware you will see an error for the mysql database. This will also fix the error message that the akonadi service generates when you start kde.

Step 1: Setup "my.cnf"

MySQL loads a config file called my.cnf at startup. This file needs to be created when you first setup MySQL. Fortunately there are several sample versions in the location . Just copy the desired version and make any desired changes to it (each one is self documented just open it in an editor for an explanation of its expected usage). # cp /etc/my-[version].cnf /etc/my.cnf

Step 2: Install Required Databases

Mysql has a required database set which it needs for itself. These are used for user identification etc. To install them use mysql user as superuser and install the initial required databases with the following command.

# su mysql # mysql_install_db

Step 3: Setup Required System Permissions

We now need to ensure that the mysql user has ownership of the mysql system. We also need to give the mysql init script permission to execute.

# chown -R mysql.mysql /var/lib/mysql # chmod 755 /etc/rc.d/rc.mysqld

Step 4: Enable Networking

If you are planning to use tcp/ip to connect to the database(s) we must make a few changes to enable networking.

Edit "/etc/my.cfn" and comment out the line that says "skip networking". Also open "/etc/rc.d/rc.mysqld" and comment out the "skip-networking" line there.

Step 5: Start MySQL

At this stage we can start MySQL with the following command.

# /etc/rc.d/rc.mysql start

Step 6: Set Root MySQL User Password

Now that MySQL is running we need to lock down the root account by setting its password.

# mysqladmin -u root password '[new-password]'

Step 7: Connect to MySQL

To ensure that our password is working, try to connect as root.

# mysql -u root -p

Step 8: Delete Empty Localhost Users

MySQL creates a set of blank user accounts for localhost. These are not needed and can be a security issue so lets delete them.

First we select the mysql database. We then get a list of all empty localhost users (just to confirm for later). Next we delete the empty user(s), note you will also have an empty user for your machines hostname, so we delete that also. Finally we rerun of select statement to confirm we have deleted them.

mysql> USE mysql; mysql> SELECT user, host FROM user; mysql> DELETE FROM user WHERE host='localhost' AND user=''; mysql> DELETE FROM user WHERE host='[hostname]' AND user=''; mysql> SELECT user, host FROM user;

Thats it you can now logout and restart the server to confirm that mysql now starts correctly with the rest of the server.