Install MySQL on Ubuntu 14.04

It’s MariaDB nowadays, but people still call it MySQL.

Just built a virtual server for databases, need of MySQL and just can’t find the notepad with commands – or better yet, no memo at all? the internet is full of tutorials, but heck, just needing the commands.

First, login as root with sudo su -. Now, let’s add the repository key.

apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db

Then, let’s install the packages which allows us to use add-apt-repository command.

apt-get install software-properties-common

Now we can add the repository.

add-apt-repository 'deb [arch=amd64,i386] trusty main'

Then we update the packages and start installing.

apt-get update && sudo apt-get -y install mariadb-server mariadb-client

It will ask you to create a root password, so give it to the setup twice. Remember to use a secure password. Now we need some configuring. Let’s backup the default config first.

cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak

Then edit the config.

nano /etc/mysql/my.cnf

You will want to tune up max_connections (for me the suitable amount is 300), and comment out bind-address. Then you can just start the MySQL server:

service mysql start

Now you can try to login with your root password, with this command:

mysql -u root -p

If you get in, you can start creating your databases. For example, if I want a database for myexampleblog, I’d add it this way

CREATE USER 'myexampleusername'@'' IDENTIFIED BY 'yourcomplicatedpassword';
GRANT ALL PRIVILEGES ON myexampledatabasename.* TO 'myexampleusername'@'';

The username, password and IP address are naturally free to choose. You can use either user your web server machine IP or allow all. If (for some reason, for example, local shared development) you want your database to be accessible from anywhere, make sure you have other security measures taken care of.

To do this, edit /etc/mysql/my.cnf, uncomment bind-address and add your server’s public IP to it. Then, add a user like this:

CREATE USER 'myexampleusername'@'%' IDENTIFIED BY 'mycomplicatedpassword';
GRANT ALL PRIVILEGES ON *.* TO 'myexampleusername'@'%';

Then quit with ^C or by typing \q. You should now be good to go and connect your applications or WordPress or anything to the database with username, server IP, database name and password. I prefer Sequel Pro for viewing the databases.

Want to write with me?

Do you know something about tech, nerdy stuff, movies, code, AI, Internet phenomena, social media or anything related to geeky subjects? Join and write with me! I'm currently doing this alone and my time is not sufficient for upkeeping the blog by myself, so all pieces of articles are welcome. Contact me and get your user account.

Roni Laukkarinen

Roni Laukkarinen

Editor-in-chief and owner of Geeky Lifestyle blog. Truly a jack of all trades, a Swiss knife; an avid tech and multimedia geek, coder, owner of a digital agency company, sysadmin, music enthusiast, artist and film critic.

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow The Geek

Geeky Lifestyle is a huge tweeter! Follow @thatgeekyblog to get real-time updates about what's happening in the scene.