sql-info.de
March 11, 2013

MySQL | Installing MySQL on a Ubuntu/Debian server

Some quick notes on installing MySQL 5 on a Debian or Ubuntu server using the command line.

1. Determine the available MySQL version(s)

This step is optional; to find out what MySQL versions are available, execute

root@server ~ # apt-cache search mysql-server
auth2db - Powerful and eye-candy IDS logger, log viewer and alert generator
mysql-cluster-server - MySQL database server (metapackage depending on the latest version)
mysql-cluster-server-5.1 - MySQL database server binaries
torrentflux - web based, feature-rich BitTorrent download manager
mysql-server - MySQL database server (metapackage depending on the latest version)
mysql-server-5.1 - MySQL database server binaries
mysql-server-core-5.1 - MySQL database core server files
cacti - Frontend to rrdtool for monitoring systems and services

Normally the mysql-server package will exist as a meta package which will install the latest MySQL version available on the system - in this case 5.1.

2. Install the mysql-server package

This will install the client packages as well:

root@europa ~ # apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-2.6.32-29 linux-headers-2.6.32-29-server
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libdbd-mysql-perl libhtml-template-perl mysql-client-5.1 mysql-client-core-5.1 mysql-server-5.1 mysql-server-core-5.1
Suggested packages:
  libipc-sharedcache-perl tinyca
The following NEW packages will be installed:
  libdbd-mysql-perl libhtml-template-perl mysql-client-5.1 mysql-client-core-5.1 mysql-server mysql-server-5.1 mysql-server-core-5.1
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 21.4MB of archives.
After this operation, 53.9MB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 http://mirror.example.com/ubuntu/packages/ lucid/main libdbd-mysql-perl 4.012-1ubuntu1 [137kB]
Get:2 http://mirror.example.com/ubuntu/packages/ lucid-updates/main mysql-client-core-5.1 5.1.67-0ubuntu0.10.04.1 [167kB]
Get:3 http://mirror.example.com/ubuntu/packages/ lucid-updates/main mysql-client-5.1 5.1.67-0ubuntu0.10.04.1 [8,792kB]
Get:4 http://mirror.example.com/ubuntu/packages/ lucid-updates/main mysql-server-core-5.1 5.1.67-0ubuntu0.10.04.1 [5,030k
Get:5 http://mirror.example.com/ubuntu/packages/ lucid-updates/main mysql-server-5.1 5.1.67-0ubuntu0.10.04.1 [7,105kB]
Get:6 http://mirror.example.com/ubuntu/packages/ lucid/main libhtml-template-perl 2.9-1 [65.8kB]
Get:7 http://mirror.example.com/ubuntu/packages/ lucid-updates/main mysql-server 5.1.67-0ubuntu0.10.04.1 [71.7kB]
Fetched 21.4MB in 1s (11.1MB/s)    
Preconfiguring packages ...

At this point a text-based dialogue box will pop up requesting the input and confirmation of a root password for the MySQL server installation (this is not connected with the server's root password):

Installing MySQL on a Ubuntu/Debian server - setting the root password

Installing MySQL on a Ubuntu/Debian server - confirming the root password

Once the password is confirmed, installation will continue:

Selecting previously deselected package libdbd-mysql-perl.
(Reading database ... 78279 files and directories currently installed.)
Unpacking libdbd-mysql-perl (from .../libdbd-mysql-perl_4.012-1ubuntu1_amd64.deb) ...
Selecting previously deselected package mysql-client-core-5.1.
Unpacking mysql-client-core-5.1 (from .../mysql-client-core-5.1_5.1.67-0ubuntu0.10.04.1_amd64.deb) ...
Selecting previously deselected package mysql-client-5.1.
Unpacking mysql-client-5.1 (from .../mysql-client-5.1_5.1.67-0ubuntu0.10.04.1_amd64.deb) ...
Selecting previously deselected package mysql-server-core-5.1.
Unpacking mysql-server-core-5.1 (from .../mysql-server-core-5.1_5.1.67-0ubuntu0.10.04.1_amd64.deb) ...
Selecting previously deselected package mysql-server-5.1.
Unpacking mysql-server-5.1 (from .../mysql-server-5.1_5.1.67-0ubuntu0.10.04.1_amd64.deb) ...
Selecting previously deselected package libhtml-template-perl.
Unpacking libhtml-template-perl (from .../libhtml-template-perl_2.9-1_all.deb) ...
Selecting previously deselected package mysql-server.
Unpacking mysql-server (from .../mysql-server_5.1.67-0ubuntu0.10.04.1_all...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
Setting up libdbd-mysql-perl (4.012-1ubuntu1) ...
Setting up mysql-client-core-5.1 (5.1.67-0ubuntu0.10.04.1) ...
Setting up mysql-client-5.1 (5.1.67-0ubuntu0.10.04.1) ...
Setting up mysql-server-core-5.1 (5.1.67-0ubuntu0.10.04.1) ...
Setting up mysql-server-5.1 (5.1.67-0ubuntu0.10.04.1) ...
mysql start/running, process 14769

Setting up libhtml-template-perl (2.9-1) ...
Setting up mysql-server (5.1.67-0ubuntu0.10.04.1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

3. Verify installation

MySQL is now installed and running; and the root account can be accessed using the password previously set:

root@europa ~ # mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.1.67-0ubuntu0.10.04.1 (Ubuntu)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

mysql> 

In more recent Ubuntu installations (certainly since 10.4LTS), the MySQL server will automatically be added as an upstart service.

And that's all there is to it.

Posted at 2:43 AM