How To Install MySQL On A VPS

Looking for a simple, stable and significant VPS as your web hosting? Check out DigitalOcean, only $5 per month, and you can get $10 in credit just for signing up now.

When installing Nginx with PHP, we only need MySQL to run WordPress on a VPS. So, how to install MySQL?

You can just enter the following command in your Terminal and install MySQL from your Ubuntu VPS directly:

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

But in this way, you won’t get the latest version, instead, you can refer to the official tutorial, or use the following 8 detailed steps to install the latest MySQL from source on your VPS:

Step 1. Install the dependencies

Enter the following command:

apt-get install libncurses5-dev cmake build-essential

Tips: You don’t need to install build-essential if you’ve installed Nginx and PHP before.

Step 2. Create a user for MySQL

Enter the following command to add a group first:

groupadd mysql

Then enter the following command to add a user:

useradd -r -g mysql mysql

Then you can start to install MySQL with a mysql database.

Step 3. Install MySQL

Let’s download MySQL from source into the opt directory with the following commands:

cd /opt

wget http://mysql.mirrors.hoobly.com/Downloads/MySQL-5.5/mysql-5.5.16.tar.gz

tar zxvf mysql-5.5.16.tar.gz

cd mysql-5.5.16

cmake .

make

make install

Tips: 5.5.16 is the latest stable version, and you can get more versions in the MySQL download page, remember to choose from the Source Code platform.

By the way, you can remove the mysql-5.5.16.tar.gz file and the mysql-5.5.16 folder to save some Disk Usage with the following commands:

cd /opt

rm -f mysql-5.5.16.tar.gz

rm -r mysql-5.5.16

P.S. There may be already mysql-common package in some Ubuntu system, in that case, you need to remove the my.cnf file first with the following command:

rm -f /etc/mysql/my.cnf

Step 4. Configure MySQL

Let’s change the ownership of MySQL 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

Step 5. Start MySQL

You can start the MySQL server with the following command:

bin/mysqld_safe --user=mysql &

Just press the Return key when seeing something like the following:

111009 23:16:18 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

Step 6. Create MySQL password

./bin/mysql_secure_installation

Then follow the instructions, set your password, and answer y to all the yes or no questions. You will see a thank you message, then you can use the database mysql with the user root and the password you set up.

Tips: If something goes wrong, you can try to reboot your VPS and restart from Step 5.

Step 7. Test MySQL

You can enter the following command:

bin/mysqlshow mysql -u root -p

And enter your root password, then you will see the tables of the mysql database if the installation is successful.

Step 8. Make MySQL auto-start

Copy the mysql.server to the init.d folder and make it start automatically with the following two commands:

cp support-files/mysql.server /etc/init.d/mysql.server

update-rc.d -f mysql.server defaults

Then the MySQL service will run automatically when your VPS reboots.

Obviously, MySQL is not easy to use with Terminal by entering commands, but we can make it easy by installing PHPMyAdmin, which is a visional control panel for MySQL.

Spread the love
This entry was posted in Other Free Nuts and tagged , , . Bookmark the permalink.