
This week we will be going over installing the database software MySQL. MySQL is one of the most popular databases and used by quite a lot of software written in PHP (WordPress, for example). It is important to note that you should be installing this software in the order we write these articles, as some software depends on other software.
Okay, as usual, start out by logging into your server via SSH. Now, head on over to the MySQL 5.1 download page and get a download link from the “Pick a Mirror” link beside Linux (x86). Then run the following command (replacing URL with the URL you just got from the MySQL site). This article assumes that you’re running this command when in the directory /.
wget URL
Now, we need to add a user and group for MySQL to run under. To do this, run the following commands:
groupadd mysql
useradd -g mysql mysql
Now, let’s switch to the directory where we we be installing MySQL to:
cd /usr/local
Now, we need to extract the .tar.gz file we downloaded in the first step. Replace mysql-VERSION-OS.tar.gz with the name of the archive you downloaded.
tar zxvf /mysql-VERSION-OS.tar.gz
So, now we will create a symbolic link that will allow us to have a shorter path to our MySQL installation.
ln -s mysql-VERSION-OS mysql
Change our working directory to our mysql files:
cd mysql
We now need to change the permissions and ownerships of these files to be under the mysql user and group:
chown -R mysql .
chgrp -R mysql .
MySQL now needs to be setup, we do this by running this command:
scripts/mysql_install_db --user=mysql
After we have run the setup, we need to remove some anonymous users and give the root user a password. Let’s start off with removing the anonymous users:
mysql -u root
DROP USER '';
Now, let’s set a password for the root user. Replace newpwd with a strong, secure password. Remember, if this password is hacked, the attacker will have full root access to all your databases.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
You can now press Control-C to exit out of the mysql command line. We can now start our MySQL server by issuing the following command:
bin/mysqld_safe --user=mysql &
Conclusion
Next week we’ll be going over how to install PHP, after that we’ll be going over some configuration stuff.




