«

»

Dec 12

How to: Install MySQL in an Ubuntu Server

How to: Install MySQL in an Ubuntu Server

If you are looking into deploying MySQL as part of a “LAMP” installation or whatever flavors you like best, Ubuntu is a good OS to do so. I say that because they make the installation super easy from the command line with apt-get, it doesn’t get much simpler than that.

I recommend installing MySQL the following way:

  1. Get the latest updates before you install
    • sudo apt-get update
  2. Run apt-get to install MySQL
    • sudo apt-get install mysql-server
  3. Type your root password for MySQL. Don’t forget to write it down or whatever you need to do
  4. You’re done!

If you wanted to verify the network bindings that MySQL has in place you can execute the following command:

sudo netstat -tap | grep mysql

which in return will show something similar to this:

tcp 0 0 localhost:mysql : LISTEN 3040/mysqld

If you encounter any issues remember mysql runs as a service so you can stop, start or restart if you want using the following command:

sudo service mysql stop|start|restart

There are more than a few settings you can specify in the configuration file for MySQL. Remember that every time you make a change you are going to have to restart the service.


Configuration

You can edit the /etc/mysql/my.cnf file to configure the basic settings — log file, port number, etc. For example, to configure MySQL to listen for connections from network hosts, change the bind-address directive to the server’s IP address:

bind-address            = 10.0.0.5

Replace 10.0.0.5 with the appropriate address.

After making a change to /etc/mysql/my.cnf the MySQL daemon will need to be restarted:

sudo service mysql restart

If you would like to change the MySQL root password, in a terminal enter:

sudo dpkg-reconfigure mysql-server-5.5

The MySQL daemon will be stopped, and you will be prompted to enter a new password.


 

Percona Server

Percona Server 5.6 is the latest release of our enhanced, drop-in replacement for MySQL®. The new version offers all the improvements found in MySQL 5.6 Community Edition plus scalability, availability, backup, and security features found only in MySQL 5.6 Enterprise Edition, which requires a support contract from Oracle to access. The free download of Percona Server 5.6 also includes superior diagnostics and improved integration with other Percona software.

I have been doing some research into how to fine tune my database server as the response rate I was getting was slow enough to be noticed across the board. There are tools like mysqltuner which I’ll cover later on but after much reading I came across Percona Server. As you can read from the introduction of their 5.6 version it is based on MySQL but with additions that make it perform better. I am recommending now installing Percona Server over MySQL in order to get the added benefits. It is a drop in replacement, which means your clients can use Percona server with out knowing it is not their vanilla MySQL server.

In order to install Percona server, do it on a clean server that doesn’t make MySQL already installed (or remove MySQL but don’t forget to backup your db). Below are the simple instructions to install Percona Server:

I. Add the Repo

apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A

echo "deb http://repo.percona.com/apt lsb_release -cs main" >> /etc/apt/sources.list.d/percona.list

echo "deb-src http://repo.percona.com/apt lsb_release -cs main" >> /etc/apt/sources.list.d/percona.list

apt-get update

Note: ‘lsb_release -cs’ will automatically place your current version on your sources.list.d file. If for some reason you get 404 errors like the ones below, it probably means that didn’t work for whatever reason. Simply put in your version instead and you’re done!

Err http://repo.percona.com lsb_release/-cs Sources
404 Not Found
Hit http://archive.ubuntu.com saucy-backports/universe i386 Packages
Err http://repo.percona.com lsb_release/main Sources
404 Not Found
Get:10 http://security.ubuntu.com saucy-security/multiverse amd64 Packages [1,160 B]
Hit http://archive.ubuntu.com saucy-backports/multiverse i386 Packages
Err http://repo.percona.com lsb_release/-cs amd64 Packages
404 Not Found
Hit http://archive.ubuntu.com saucy-backports/main Translation-en
Err http://repo.percona.com lsb_release/main amd64 Packages
404 Not Found
Get:11 http://security.ubuntu.com saucy-security/main i386 Packages [104 kB]
Hit http://archive.ubuntu.com saucy-backports/multiverse Translation-en
Err http://repo.percona.com lsb_release/-cs i386 Packages
404 Not Found
Err http://repo.percona.com lsb_release/main i386 Packages
404 Not Found

[…]

W: Failed to fetch http://repo.percona.com/apt/dists/lsb_release/-cs/source/Sources 404 Not Found

W: Failed to fetch http://repo.percona.com/apt/dists/lsb_release/main/source/Sources 404 Not Found

W: Failed to fetch http://repo.percona.com/apt/dists/lsb_release/-cs/binary-amd64/Packages 404 Not Found

W: Failed to fetch http://repo.percona.com/apt/dists/lsb_release/main/binary-amd64/Packages 404 Not Found

W: Failed to fetch http://repo.percona.com/apt/dists/lsb_release/-cs/binary-i386/Packages 404 Not Found

W: Failed to fetch http://repo.percona.com/apt/dists/lsb_release/main/binary-i386/Packages 404 Not Found

E: Some index files failed to download. They have been ignored, or old ones used instead.

Template:

deb http://repo.percona.com/apt VERSION main
deb-src http://repo.percona.com/apt VERSION main

Example for Ubuntu 13.10 Saucy Salamander:

deb http://repo.percona.com/apt saucy main
deb-src http://repo.percona.com/apt saucy main

II. Install the Server

apt-get install percona-server-server-5.6

III. (Optional) Install the Client

apt-get install percona-server-client-5.6

IV. Reset the root password in case you forget it (you will need the client installed)

mysqladmin -u root password MYNEWPASSWORD

Enjoy a faster MySQL experience!

 

Enhanced by Zemanta

Leave a Reply

%d bloggers like this: