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.

Thanks for reading! I need your attention for a moment.

Did your problem got solved? Did you enjoy this post? If so, consider thanking me on Patreon. Doing this is not free and I'd love you buy me a beer or coffee. If you do that, I might be able to help you if you didn't get your problem solved with this blog post. I know my shit around areas like website design, coding, blogging, digital marketing and SEO so if you want to do business with me in other ways let me know.

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.