Setup and configure MYSQL in Slackware Linux

Mysql is a popular open source database which being used as database server by many organizations around the world. Normally, Mysql is used together with PHP server-side scripting language, Apache web server and Linux as the server platform. This tutorial is a step by step guide on how to setup and configure mysql in Slackware Linux. If you are looking for this, then let's get started now.

First thing to do is to check whether mysql user and mysql group already exist in the system. You should have them if you installed mysql package during Slackware 12.2 installation.

root@slackware:~# less /etc/passwd | grep mysql
mysql:x:27:27:MySQL:/var/lib/mysql:/bin/false
root@slackware:~#
root@slackware:~# less /etc/group | grep mysql
mysql:x:27:

Create new mysql user and mysql group if you don't have them. Learn how to create a new user in Slackware with Linux adduser command - add new user account in Linux system tutorial. You can find information about Linux group in groupadd command - manage groups in Linux system tutorial.

Check if a directory name mysql exist in /var/run directory.

root@slackware:~# ls /var/run/ | grep mysql
mysql/
root@slackware:~#

Create a new directory named mysql in /var/run directory if it's not there. Learn how to create new directory in Slackware in mkdir tutorial. When you are done, check mysql directory ownership. It must be owned by mysql user and mysql group.

root@slackware:~# ls -l /var/run/ | grep mysql
drwxr-xr-x 2 mysql mysql 4096 2008-10-05 13:29 mysql/
root@slackware:~#

You can change directory ownership with Linux chown command. See the example below:

root@slackware:~# chown -R mysql.mysql /var/run/mysql/
root@slackware:~#

Install or upgrade mysql package in your Slackware system. See example on how to install mysql using slackpkg command below:

root@slackware:~# slackpkg install mysql

Looking for mysql in package list. Please wait... DONE

No packages match the pattern for install. Try:

/usr/sbin/slackpkg reinstall|upgrade

If you see the same result as the example above, try running the command again but using slackpkg upgrade option instead. Don't worry if you see the same result again. You probably have mysql installed and upgrade to the latest version already. You can confirm it by checking the installed packages in log directory. See the example below:

root@slackware:~# ls -l /var/log/packages/ | grep mysql
-rw-r--r-- 1 root root 8159 2009-02-28 01:25 mysql-5.0.67-i486-1

Configure mysql in Slackware 12.2

There is a slight different on how to configure mysql in Slackware 12.2. You can follow the step by step mysql configuration example below:

Create mysql user and mysql group:

  1. root@slackware:~# groupadd mysql
  2. root@slackware:~# useradd -G mysql -d /var/lib/mysql -s /bin/false mysql

You can also use usermod command to add mysql user to mysql group if mysql user already exist. See the example below:

root@slackware:~# usermod -G mysql mysql
root@slackware:~# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)

You have to create a new mysql configuration file called my.cnf. This can be done easily by copying the example (existing) configuration files in the /etc directory. You can view all available mysql configuration files in /etc directory using grep command. See the example below:

root@slackware:~# ls -l /etc/ | grep my
-rw-r--r-- 1 root root 4972 2008-10-05 13:29 my-huge.cnf
-rw-r--r-- 1 root root 4948 2008-10-05 13:29 my-large.cnf
-rw-r--r-- 1 root root 4955 2008-10-05 13:29 my-medium.cnf
-rw-r--r-- 1 root root 2525 2008-10-05 13:29 my-small.cnf
root@slackware:~#
root@slackware:~# cp /etc/my-medium.cnf /etc/my.cnf

Create mysql database as Slackware 12.2 recommended:

root@slackware:~# mysql_install_db --user=mysql
Installing MySQL system tables...
090423 12:35:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
090423 12:35:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK
Filling help tables...
090423 12:35:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
090423 12:35:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h slackware password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
root@slackware:~#

To start mysql daemon at boot time, we can change the mysqld script file permission, the /etc/rc.d/rc.mysqld.

root@slackware:~# chmod 755 /etc/rc.d/rc.mysqld
root@slackware:~# ls -l /etc/rc.d/ | grep mysqld
-rwxr-xr-x 1 root root 2585 2008-10-05 13:29 rc.mysqld*

Create password for mysql root user:

root@slackware:~# /usr/bin/mysqladmin -u root password 'new_password'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysql/mysql.sock' exists!

Opss...we got an error there. We forgot to start mysql daemon (mysql server) first. Let's start the server now:

root@slackware:~# /usr/bin/mysqld_safe &

Now we can create password for root user by invoking the command again. However, before you do that, here is another option. There is a tool that provide basic security for mysql including setup root password that you can run. The tool is mysql_secure_installation. It's recommended you run this command. See the example below:

root@slackware:~# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] Y
... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

root@slackware:~#

That's it. The mysql server is ready. We can test login and create a new database.

Testing mysql

We can test login into mysql now:

luzar@slackware:~$ mysql
ERROR 1045 (28000): Access denied for user 'luzar'@'localhost' (using password: NO)
luzar@slackware:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.67-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

To view databases, we can use SHOW DATABASES command:

mysql> SHOW databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)

mysql>

We can create a new database with CREATE DATABASE command. See the example on how to create a new database below:

mysql> CREATE DATABASE basicconfig
-> ;
Query OK, 1 row affected (0.00 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| basicconfig |
| mysql |
+--------------------+
3 rows in set (0.00 sec)

mysql>

We can delete a database with DROP DATABASE command. See the example on how to drop a database example below:

mysql> DROP DATABASE basicconfig;
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)

mysql>

Finally, to exit mysql, use QUIT command or \q command:

mysql> QUIT
Bye
luzar@slackware:~$

Uninstall mysql and remove mysql data

I don't know what your reason is, but if you need to remove mysql from Slackware, here are steps that you need:

Stop mysql service:

root@slackware:~# killall -9 mysqld mysqld_safe
[1]+ Killed /usr/bin/mysqld_safe
root@slackware:~#

Uninstall mysql using slackpkg:

root@slackware:~# slackpkg remove mysql

Remove remaining mysql data and directory.

root@slackware:~# rm -r /var/lib/mysql/
root@slackware:~# rm /etc/my.cnf

Run updatedb command and invoke locate mysql to find remaining mysql data if you want.

That's all. Good luck!

Slackware 14.1 drop mysql and use MariaDB instead. If you are looking for that, you can read a tutorial on how to Configure MariaDB in Slackware 14.1.

Comments

3

Very nice article. I was able to install and configure mysql server on Slackware 13 without any problem using your description.
Thank you!
Gabi

PS: would be nice to add some details regarding the location of the installed server and the data storage directory (where the databases are stored). I preferred installing from source to be able to control where the databases are stored !

It's hard to find step by step tutorials for mariadb, but your tutorials really works.

Thanks for the comment. I am glad it works for you. Actually we have a tutorial on how to configure MariaDB in Slackware 14.1. Already added the link in the tutorial for everyone else.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.