How to Install and Setup MySQL on CentOS

This article describes basic installation of MySQL database server on CentOS 6. You might need to install other packages to let applications use MySQL, i.e PHP.

Installing and Setting up MySQL database Server:

1To install MySQL, input the following yum command:

yum -y install mysql-server

2To enable MySQL daemon to start on boot:

chkconfig mysqld on
or
/usr/bin/chkconfig mysqld on

3Start the service:

service mysqld start
or
/etc/init.d/mysqld start

4You should secure MySQL with the following command:

mysql_secure_installation
or
/usr/bin/mysql_secure_installation

5 – Script will assist you with this process by presenting several questions. Recommended default action is to select YES for all questions.The command prompt will ask for your current MySQL root password. Leave it blank by pressing ENTER.

Answer the command prompt as specified below:

Set root password? [Y/n] Y
New password: YourOwnPassword
Re-enter new password: YourOwnPassword
Remove anonymous user? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Login to MySQL:

1After successfully installing MySQL, login as root user:

mysql -u root -p mysql

2Give the password we have assigned when we ran the secure script, when prompted.

3Create new User and Database:

mysql> CREATE DATABASE demodb;
mysql> GRANT ALL ON demodb.* TO 'demouser'@'localhost' IDENTIFIED BY 'password';
mysql> QUIT;

4Connect to MySQL new database and user:

mysql -u demouser -p demodb

Adding MySQL port in iptables of CentOS:

1To edit /etc/sysconfig/iptables file, enter:

vi /etc/sysconfig/iptables

2Now append the following code to open tcp port 3306 for MySQL:

-A INPUT -m state –state NEW,ESTABLISHED -m tcp -p tcp –dport 3306 -j ACCEPT

3Save and close the file and restart iptables by giving following command:

service iptables restart

  • How to Install and Setup MySQL on CentOS
  • 0 A felhasználók hasznosnak találták ezt
Hasznosnak találta ezt a választ?

Kapcsolódó cikkek

Setting up a Name Server for IPv6 rDNS in CentOS

Managing your own IPv6 rDNS is a fairly simple task. After setting up the name server, please...

Reset the Root Password in CentOS

If you have forgotten the root password it is possible to set a new one by interrupting the boot...

How to Install and Configure vsftpd on CentOS 7

FTP (File Transfer Protocol) is one of the most popular methods to upload files to a server....

How to enable EPEL repository?

The EPEL repository is an additional package repository that provides easy access to install...

Find (View) Default Zone for Firewall on CentOS 7

Pre-Flight Check These instructions are intended for finding (viewing) the default zone in...