Setting Up a MySQL Server on Slackware

Posted by: Andrew Smith
Poster contact info: andrew-smith at mail ru
Author: Flea, MySQL team, Andrew Smith
Originally published: http://www.linuxpackages.net/forum/ http://dev.mysql.com/doc/mysql/en/default-privileges.html
Software: Slackware 9.1, Slackware 10.0, Slackware 10.1

Spent some time to make a more complete guide on easy, basic MySQL setup on a Slackware box. The two sources above were very helpfull, I especially recommend looking in the MySQL reference manual when you're lost.

So, the MySQL server doesn't work even though it came as an official package with Slackware? Here's what you need to do (all of this should be done as root):

1: Create grant tables (and whatever else)
You need to be user mysql so mysql owns the files you create:
su - mysql
mysql_install_db
exit

2: Start the server to set passwords
First choose one of /etc/my-* files to use as a config file. If you don't know or care, use the small one:
cp /etc/my-small.cnf /etc/my.cnf

MySQL comes with an rc script. We will copy this to where slackware expects it to be, make it executable so it runs on boot and start the server:
cp /usr/share/mysql/mysql.server /etc/rc.d/rc.mysqld
chmod a+x /etc/rc.d/rc.mysqld
/etc/rc.d/rc.mysqld start

3. Mess with default authentication
By default MySQL has two root users (one for localhost and one for yourhostname) and two anonymous users. All of them have blank passwords.

Login to your new server:
mysql -u root

If you aren't sure about the hostname, ask the server:
mysql> SELECT Host, User FROM mysql.user;

Change the root passwords (remember to replace yourhostname and new-password, single quotes are necessary):
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password');
mysql> SET PASSWORD FOR 'root'@'yourhostname' = PASSWORD('new-password');

I recommend deleting the anonymous users, it's much safer to create users when you need them:
mysql> DELETE FROM mysql.user WHERE User = '';
mysql> FLUSH PRIVILEGES;
mysql> exit

4. Enjoy
Boy, I hope you're a databases fan because that reference manual is really long and you need to read parts of it to do basic things. Here's some commands you can give it (so you don't just sit there wondering what do do :)
mysql> show databases;
mysql> show tables;
mysql> use test;

Cheers.