Search
Close this search box.

How to Install a MySQL server on CentOS

Table of Contents

In this tutorial, we will show you How to Install a MySQL server on Centos.

MySQL (officially pronounced as “My S-Q-L”) is an open-source relational database management system (RDBMS).The MySQL server software itself and the client libraries use dual-licensing distribution. They are offered under GPL version 2, beginning from 28 June 2000 or to use a proprietary license.

First, you need to have a VPS Server with CentOS operating system installed in it.Get VPS Server by following this link.

We explain how to Install MySQL Server on CentOS 6 and MariaDB in CentOS 7.

Follow the steps to successfully install MySQL Server.

Install MySQL Server

You need root access to run these commands

Install MySQL Server by running this command:

yum install mysql-server

After installing, start the MySQL server :

sudo /sbin/service mysqld start

 

Now run this command:

sudo /usr/bin/mysql_secure_installation

When prompt for password press ENTER to leave it as blank.And answer as Yes to all prompts.

Now you successfully installed MySQL server.

To start it run this command:
sudo /sbin/service mysqld start

And to stop it run this command:
sudo /sbin/service mysqld stop

To enable chkconfig run this command:
sudo chkconfig mysqld on

Install MariaDB in CentOS 7

Install MariaDB by running this command:
yum install mariadb-server mariadb

After installing, allow the remote access by tunning these commands:
iptables -I INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -I OUTPUT -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

You successfully installed MariaDB.

To start Maria DB run this command:
sudo systemctl start mariadb.service

And to stop it, run this command:
sudo systemctl stop mariadb.service

To enable chkconfig in Maria DB run this command:
sudo systemctl enable mariadb.service

Set password

To set a password for MySQL Server and MariaDB run this command:
/usr/bin/mysqladmin -u root password 'new-password'

If you are not logged to your database server run this command
/usr/bin/mysqladmin -u root --password='new-password' -h hostname-of-your-server 'new-password'

Start the MySQL shell and create database

To start the MySQL shell and create a database are same commands.

For starting MySQL shell run this command
mysql -u root -p

When prompt for a password, press Enter if you left it as blank.

After starting MySQL shell you can create a database.
To create database follow these commands in a shell:

CREATE DATABASE vpsiedb;
CREATE USER 'vpsieuser'@'localhost' IDENTIFIED BY 'vpsiepassword';
GRANT ALL PRIVILEGES ON vpsiedb.* to vpsieuser@localhost;
FLUSH PRIVILEGES;

And type quit, to close the shell.

You have successfully installed MySQL Server and MariaDB.
Enjoy!

Make a Comment
Share on
Facebook
Twitter
LinkedIn
Print
VPSie Cloud service

Fast and Secure Cloud VPS Service

Try FREE
For a month

The First 1 orders gets free discount today! Try Sign up on VPSie to get a chance to get the discount.