Home / Articles

MySQL installation

2014-05-28T07:11:00Z.

MySQL is a popular, free and open source RDBMS. This article covers basic installation and configuration of MySQL server and client program. This article assumes MySQL is being installed on Debian GNU/Linux.

Install MySQL server

To install MySQL server, execute the following as root:


aptitude install mysql-server

The above command installs latest supported version of MySQL server. When installing MySQL server, MySQL client will also be installed.

Install MySQL client

To connect to MySQL server, MySQL client alone is sufficient. Execute the following as root:


aptitude install mysql-client

The above command installs latest supported version of MySQL client.

Configure character set used by MySQL server

Under the [mysqld] section of the configuration file /etc/mysql/my.cnf, check the following line exists:


character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

The lines above ensure that the MySQL server uses UTF-8 for databases by default. The major difference between utf8 and utf8mb4 is that, the former one uses 3 bytes per character at most and contains BMP (Basic Multilingual Plane) characters only, while the later one uses 4 bytes per character at most and supports supplemental characters. utf8mb4 is a superset of utf8. If your database is going to store characters such as Emoji, you must use utf8mb4 or the insertion of data will fail.

Restart MySQL server after modifying the configuration file by executing the following line:


/etc/init.d/mysql restart

Configure character set used by MySQL clients

Under [client] section of the configuration file /etc/mysql/my.cnf, check the following line exists:


default-character-set = utf8mb4

Under [mysql] section of the configuration file /etc/mysql/my.cnf, check the following line exists:


default-character-set = utf8mb4

The above lines ensure that the MySQL clients use UTF-8 to encode data when connecting to MySQL server.

References