Setting Up MySQL On A Linux-Based VPS

MySQLMySQL has a great deal to offer your server – there’s a reason it’s among the most widely-used database platforms in the world. Offered by the majority of Linux-based web hosts, the open-source database is incredibly fast and lightweight, in addition to being closely integrated with PHP. This makes it ideal for a wide variety of different installations including data warehouses, web hosting, web development, application management, and digital storefronts.

Even better, it’s open-source. That means that not only does it provide you with a great deal of freedom concerning how you use it, but at an incredibly low total cost of ownership. Factor in that it’s one of the more intuitive platforms on the market, and there’s a clear case in favor of installing it.

Now, it’s worth mentioning that – even though it is known to be one of the simpler database platforms in terms of usability – it isn’t necessarily easy to work with if you don’t know what you’re doing. Today, we’re going to walk you through what’s involved if you want to install MySQL onto a virtual private server. There are several ways you can do this, and which one you use depends on what your server’s running your server is using (via the MySQL Dev Site)

Installing MySQL

Check Your Repository

The first step in the installation process – regardless of which Linux system you’re using – is to make sure your repository is up-to-date (or that you have one installed).

Using the Yum Repository(Fedora)

Your first step is to add the Yum repository to your installation’s repository list. First, go to the MySQL Yum Repository page. After downloading the relevant package, install it using the following command. Replace the first asterisk with your platform information (on Fedora 20, for example, you’d enter fc20), and the second star with the version number of the MySQL installation.

shell> sudo yum localinstall mysql-community-release-*(*).rpm.

Note that on an EL-5 based system, you’ll need to type sudo rpm –Uvh instead of simply sudo yum.

Once you’ve installed the repository, the next step is simple: simply type shell> sudo yum install mysql-community-server.

Using The APT Repository(Debian, Ubuntu)

The process for installing MySQL with the APT repository is very similar to the process you’d follow using the Yum Repository. Go here to download your platform’s release package, then run the following command(again, replace the * with your specific version’s information):

shell> sudo dpkg –i mysql-apt-config_0.1.5-*.deb

During the installation, you’ll be prompted to choose which major release version you want. Choose whichever best suits your needs. Once everything’s on your system, the following command will install your database:

shell> sudo apt-get install mysql-server

Using Oracle’s Debian Packages (Debian 7, Ubuntu)

In lieu of the above, if you’re using Debian (or a Debian-esque) system, you can install one of Oracle’s Debian packages, available here or here. First, make sure the libaio library is installed on your system with the following command:

shell> sudo apt-get install libaio1

Next – once you’ve downloaded one of the tarball bundles from one of the above sources – you’re going to unpack it by entering:

shell> tar -xvf mysql-server_MVER-DVER_CPU.deb-bundle.tar

In this case, MVER represents the version of MySQL and DVER represents the Linux distribution’s version.

Finally, you’ll want to install the four deb packages included in the bundle, in the following order:

Database common files: shell> sudo dpkg -i mysql-common_MVER-DVER_CPU.deb
MySQL Server: shell> sudo dpkg -i mysql-community-server_MVER-DVER_CPU.deb
MySQL Client: shell> sudo dpkg -i mysql-community-client_MVER-DVER_CPU.deb
Shared Client Library: shell> sudo dpkg -i libmysqlclient18_MVER-DVER_CPU.deb

Using Your Native Repository(Fedora, CentOS, Debian, Ubuntu)

The last – and simplest – installation method is to simply use the built-in software repository that shipped with your Linux installation. You’ll be using commands very similar to the above entries. In all cases, you’ll first want to make sure your repository is completely up-to-date.

That can be accomplished by entering either sudo apt-get update or following the instructions outlined here. Once your repository is completely updated, you’ll move on to the installation process.

On Fedora and CentOS, you’ll be using:

root-shell> yum install client-tools server-tools library-tools

On Debian or Ubuntu, you’ll be using:

root-shell> apt-get install packageidentifier

Setting Up MySQL

Once you’ve installed MySQL, your next step is to set it up and configure it. This process is essentially the same regardless of which distribution you’re using. Run the command shell> sudo mysql_secure_installation. You’ll be faced with a number of prompts. Generally, it’s a good idea to reply with yes to all of them, save perhaps for allowing the root user to log in remotely (you are installing this on a virtual private server, after all).

Configuring MySQL(Post Installation)

Finally, once you’ve installed and set up your installation, there are a few configuration issues you’ll need to attend to:

  • Change your installation’s ownership details with the following commands:
    • cd /usr/local/mysql
    • chown -R mysql .
    • chgrp -R mysql .
    • scripts/mysql_install_db –user=mysql
    • chown -R root .
    • chown -R mysql data
  • If you want to connect to MySQL from another machine, you’ll need to enable iptables and open up the necessary ports.
  • You may want to configure MySQL to run at boot. The command to do so is sudo chkconfig mysqld on.
  • Troubleshoot and test the server before going into production mode. You can do that with sudo bin/mysqlshow mysql -u root -p
  • Set up your grant tables.

Anyway, that’s it for the basic manual installation process. There’s a lot more to learn about MySQL – more than we’ve the time or space to discuss here. Thankfully, there’s a plethora of excellent guides and tutorials online, coupled with an immensely helpful community that’s perfectly willing to address whatever questions or concerns you might have about your new database. You can also reach out to Futurehosting’s own support team as well, if you like – after all, that’s what they’re here for.

Matthew Davis is a technical writer and Linux geek for Future Hosting.

Dedicated Server Special

Take advantage of our Double RAM offer on the E3-1230v2 4 x 3.30GHz+HT server! Only $134.95 per month. Managed and Unmanaged options available at checkout.

GET STARTED