Basic Guide: Install MySQL Server On CentOS
| |Easy and simple way to install MySQL on CentOS VPS or Dedicated server. A guide posted for newbie to learn how to build working server to host a website. MySQL is part of either LAMP or LNMP stack. I shared already about how to install Apache web server and PHP5 on CentOS, today you will see how to get MySQL installed on your server as well so you will have fully LAMP stack installed. We will talk about Nginx in another post.
MySQL plays important role in many dynamic website nowadays because it provides a solid platform to use, store, manage, organize and querying database. Yet, it is also lightweight. Without further chit chat, follow steps below to install MySQL on your server.
Requirements
- A working CentOS server. In this guide I am using CentOS 6.3 x32 (see my playground server)
- Windows users should download Putty while Mac and Linux users can simply use Terminal
- You’ll also need a basic skill to use Putty and to navigate through SSH. Read: Most common Unix commands used to SSH.
- About 15 minutes of your time and a cup of tea if you like.
Step 1 – Login to your server and follow my previous guide about Basic setup for CentOS before you build a live web server. You may and may not follow that tutorial but if you followed, it will give you some basic security tweak to your server.
Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch as root.
Step 2 – Install MySQL using yum on CentOS. Issue following command:
yum install mysql-server
Type the basic command above and hit Enter. Screenshot:
It will ask for confirmation, simply type Y then hit Enter again:
Once done it’ll display the Complete! message:
Step 3 – Alright! You’ve installed MySQL on your server. It’s time to start MySQL main service. Issue this command
service mysqld start
As usual, it should display the OK message indicating everything’s fine:
Step 4 – Setup MySQL root password. Your server has “root” user but MySQL also has its own. It means your server’s root password is not similar as root password for MySQL. Go ahead set a root MySQL password by issuing this command:
/usr/bin/mysql_secure_installation
It will then ask you to enter current password. As you never set it up previously, so simple hit Enter (because currently there is no password).
Next, you’ll be asked: Set root password? [Y/n]. Type Y and hit Enter then type in your new password twice.
Yet, you’ll also be asked for several questions. Simply answer with Y to move on.
Remove anonymous users? [Y/n] y ... Success! Disallow root login remotely? [Y/n] y ... Success! Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reload privilege tables now? [Y/n] y ... Success!
At the end, it will say: Thanks for using MySQL!
That’s it. Now your server is really ready to host a website as it already has Apache, MySQL and PHP installed on it.
Necessary read:
Top Most Common Basic MySQL Commands.
Do not hesitate to drop a comment below with questions, opinion, tips and tricks of your own. For quick and easy update you can follow me on Twitter.
Great tut!
I have just started read your blog , and i have question about optimalize operating system now my OS take about 100mb of ram, can you write some article about removing unnecessary programs which take a memory ?
Thank you a lot!
Lots of thank to this straight guide. it’s really useful to me.
Now I’m writing a step by step instruction for myself based on what’s here and some other less important things i found by looking else where and try and errors to record and remember and do them faster for next servers.
Maybe it’s possible to put them together and write a bash / shell little program to do them automatically.
thanks a lot.
Mom, I have tried to install php and my sql, but it showed this
# yum install php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: http://www.gtlib.gatech.edu
* extras: mirror.anl.gov
* updates: http://ftp.linux.ncsu.edu
Setting up Install Process
No package php available.
Error: Nothing to do
# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: http://www.gtlib.gatech.edu
* extras: mirror.anl.gov
* updates: http://ftp.linux.ncsu.edu
Setting up Install Process
No package mysql-server available.
Error: Nothing to do
What should i gonna do??
This mean’s that these packages are all ready installed.
that is what this means when you see it (Error: Nothing to do)
I am getting the same error.
[root@MiCondominio ~]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.mirror.nac.net
* extras: mirror.es.its.nyu.edu
* updates: mirror.es.its.nyu.edu
No package mysql-server available.
Error: Nothing to do
[root@MiCondominio ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
In RHEL 7, and consequently in CentOS7, the mysql- packages (or most of them, anyway) have been replaced with mariadb- packages due to an upstream rename/fork. Simply yum install mariadb-server mariadb-libs mariadb and you should be okay – the command names themselves are still mostly mysql related.
Am probleme cu vps nu pot instala server msql
Nice article.
I am reading your series of: http://servermom.wpengine.com/complete-newbie-guide-to-build-centos-server-to-host-websites/
Thanks.
i get some trouble in step 4, mom
I cant input my pass, whats going on?
before that, in previuos tutorial. I get some trouble too
Could u help me, mom
Hello Sawiyati, it is very nice to get such blog that offer step by step methods. I have a question, does it necessary to install php, php-mysql etc before installing mysql server? I think it can be build from easyapache module in cpanel/whm.