Installing MySQL for Nginx

MySQL logoFollowing on from our last step in setting up an Nginx server, we need a database to store our CMS data in. What’s a good database to install on an Ubuntu server? Oh yeah, MySQL!

MySQL is a doddle to install – you simply connect via your SSH client and run the following command:

sudo apt-get install mysql-server php5-mysql mysql-client

While it’s installing, you’ll be prompted for a root password for the MySQL server. Give it a good, secure password and you’ll have to confirm the password before the installation continues. And you’ll need this later on for connecting your web app to the database, so write it down!

Setting up a database

Next, we’ll connect to the MySQL server through the command line and create a database container for our site. If you remember from our last article, we’ll be setting up a database for the spare domain, www.interwebworld.co.uk. I’m going to call this database interweb.

Connect to MySQL with the following command:

mysql -u root -p

You’ll be prompted for the root user password. Enter that and you should get a welcome screen. Now, type the following command to set up your database:

create database interweb;

As with the SSH account on your website, you don’t want to use the root account for normal operations. Therefore, you should run this command in MySQL to set up a database user with rights on the database we just created:

grant all on interweb.* to 'youruser' identified by 'yourpassword';

If you’re not comfortable working with your databases via the command line, you should also consider installing phpmyadmin – it’s easy to install through the usual repositories. There’s a little bit of setup to do to make this work, and we’ll cover that in the next exciting installment!

Well, not quite. Before phpmyadmin will run, we need to install a PHP processor. We’ll also need this for our Drupals or our WordPress CMS. So, next up we install PHP-FPM – which, like Nginx, is gaining approval in webmaster circles where they gather to talk about these types of things…

3 comments

  1. great post. i was looking to forward the mysql via nginx and got a guide to install mysql.what a wast of bandwith.and mysql guru:grant all on interweb.* to 'youruser' identified by 'yourpassword';grants the file privileg. that means if your high secruity box is rooted, they can write any file (and read) that mysql can. Not an good idea. never grant all to webusers…

    • I don’t quite understand the need for so much hostility, I’m merely sharing my notes from installing Nginx for myself. Still, I want to thank you for pointing out a pretty big security vulnerability here – you’ve opened my eyes to something I’d have otherwise overlooked!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s