20120515

Installing MySQL


Obtaining MySQL

I strongly recommend using the MySQL server package directly from your Linux distribution rather than downloading from MySQL AB unless you have a very specific reason for using a different version. If you can’t think what one of those specific reasons might be, then you probably don’t have one, and you therefore should use the MySQL server available with your distribution.

Installing MySQL on Linux

There are several distributions upon which you might find yourself installing MySQL. It’s always a challenge choosing which distributions to cover. No matter which ones we decide to cover there will always be someone installing on another distribution.

In this section I’ll examine MySQL installation on Debian, CentOS, and Ubuntu. Additionally, I’ll demonstrate compiling MySQL from source for those who don’t have a MySQL server package available with their distribution. It should be noted that because MySQL 6 is so new it may not be available as a package in your distribution. If this is the case, I recommend sticking with the latest MySQL available for your distribution. For the most part, this book will use functions available in MySQL 5 and later, so MySQL 6 isn’t a requirement. Where MySQL 6 is required, a special note will be shown.

Installing MySQL Server on Debian and Ubuntu

Debian’s dpkg and apt installation and package management tools make installation of MySQL (and everything else for that matter) incredibly easy. Debian is a system administrator’s dream because it’s so stable, package installation is so easy, and the packages are maintained and configured with excellent defaults. But enough evangelizing; installation of MySQL server on Debian requires superuser
privileges and is accomplished simply by running apt-get:

apt-get install mysql-server

Of course, that assumes that you have correctly configured sources in /etc/apt/sources.list. For more information on APT and configuration of the sources.list file, see www.debian.org/ doc/manuals/apt-howto/ch-basico.en.html. Debian’s package management system will install and configure any necessary prerequisites for you.

Debian separates MySQL into its components such as server, client, and libraries. Therefore, in order to use MySQL and PHP together, you should install the php5-mysql package:

apt-get install php5-mysql

As you can see by that installation command, the PHP5 version of the interface is being installed. That is the latest version available as of this writing.
Finally, you’ll likely also want to install the MySQL command-line interface (CLI), which is accomplished by installing the mysql-client package:

apt-get install mysql-client

MySQL will now be installed and ready to use on your Debian server. However, by default the MySQL server won’t listen on anything by localhost. To change this, edit /etc/mysql/my.cnf and comment out the skip-networking line with a pound sign or hash mark (#), so it looks like this:

#skip-networking

Now restart the MySQL server by typing this command:

/etc/init.d/mysql restart

No comments: