There are no notfications.

This article was last reviewed for Debian 8 (Jessie).

MySQL 5.5 installation and configuration (Debian, repository)

MySQL 5.5 installation and configuration (Debian, repository)
Author: Stefán Örvar Sigmundsson
Initial publication:
Last updated:
Written in: English (United Kingdom)

MySQL is the world's most popular open-source relational database management system (RDBMS). This article will demonstrate how to install and configure MySQL 5.5 on Debian or its derivatives such as Ubuntu and Linux Mint.

Installation

MySQL can be installed from the official Debian repository using APT:

root@computer:~# apt --assume-yes install mysql-server-5.5

The user is prompted during the installation for a password for the newly created root MySQL user.

Configuration

The default log files for MySQL are deleted as a new one (error.log) will be created in a dedicated directory (/var/log/mysql) for organisational purposes:

root@computer:~# rm /var/log/mysql.err
root@computer:~# rm /var/log/mysql.log

A file is created to contain the error log for MySQL in a dedicated directory:

root@computer:~# touch /var/log/mysql/error.log

A directory is created to contain the temporary files created by MySQL for various purposes:

root@computer:~# mkdir /var/tmp/mysql/

There is a lot of clutter in the default configuration file even though it is operational. Clearing it will ensure that there is no conflict nor confusion:

root@computer:~# > /etc/mysql/my.cnf

my.cnf

The my.cnf file contains MySQL's primary configuration:

[client]

port = 3306

[mysqld]

basedir = /usr

bind-address = 127.0.0.1

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

datadir = /var/lib/mysql/

log-error = /var/log/mysql/error.log

pid-file = /run/mysqld/mysqld.pid

port = 3306

socket = /run/mysqld/mysqld.sock

tmpdir = /var/tmp/mysql/

user = mysql
[client]
Sets the configuration scope for the subsequent directives to client. The client scope includes all of the client programs that come in the installed software packages so that they need no be configured individually.
port = 3306
The port to which to connect.
[mysqld]
Sets the configuration scope for the subsequent directives to mysqld. The name of the MySQL service is mysqld by default on Debian.
basedir = /usr
The base directory is /usr by default on Debian.
bind-address = 127.0.0.1
The IP address to which to listen for connections.
character-set-server = utf8mb4
The default character set for the server.
collation-server = utf8mb4_unicode_ci
The default collation for the server.
datadir = /var/lib/mysql/
The data directory of MySQL is /var/lib/mysql/ by default on Debian.
log-error = /var/log/mysql/error.log
The log file of MySQL is /var/log/mysql/error.log by default on Debian.
pid-file = /var/run/mysqld/mysqld.pid
The PID file of MySQL.
port = 3306
The port to which to listen on for connections.
socket = /run/mysqld/mysqld.sock
The socket file of MySQL.
tmpdir = /var/tmp/mysql/
A directory (/var/tmp/mysql/) is created to contain temporary files.
user = mysql
The OS user of MySQL is mysql by default on Debian.

Conclusion

Log rotation

The package installs a default logrotate configuration file (/etc/logrotate.d/mysql-server) that can be customised:

/var/log/mysql/*.log
{
	copytruncate
	maxage 365
	missingok
	monthly
	notifempty
	rotate 12
}
/var/log/mysql/*.log
Sets the configuration scope for the subsequent section. The pattern matches all files (*) ending with the extension log in the /var/log/mysql/ directory.
copytruncate
Copy the contents of the log file being rotated into a new file and then truncate the original log file.
maxage 365
Remove log files older than 365 days.
missingok
Do not consider it an error if a log file is missing.
monthly
Perform a log rotation monthly.
notifempty
Do not perform a log rotation on an empty log file.
rotate 12
Perform 12 log rotations before older log files are removed.

Directory ownership and permissions

The configuration directory should be protected:

root@computer:~# chown --recursive root:adm /etc/mysql/
root@computer:~# chmod --recursive 0770 /etc/mysql/

The log directory should be protected:

root@computer:~# chown --recursive mysql:adm /var/log/mysql/
root@computer:~# chmod --recursive 0750 /var/log/mysql/

The temporary file directory should be protected:

root@computer:~# chown --recursive mysql:mysql /var/tmp/mysql/
root@computer:~# chmod --recursive 0770 /var/tmp/mysql/

Server reinitiation

MySQL is restarted when the configuration is done:

root@computer:~# systemctl restart mysql.service

External links

This article has additional content here.