How to install MySQL in CentOs7

MySQL is a well known database management system for web based and server based applications.

MySql is RDBMS ( Relational Database Management System. It provides multi user access to the number of databases.

MySQL is no longer in CentOS’s repositories.

Now MariaDB is the default database system for CentOS7.

MariaDB is the replacement of MySQL and it is sufficient for a simple database system.

Install MySQL on CentOS7

In CentOS7 MySQL must be installed from the community repository.

Download MySQL source file and update system repository with wget command.

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
$ yum update

Install MySql Server
$ sudo yum install mysql mysql-server php-mysql

Press Y to accept installation GPG Verification

Start MySql
$ sudo systemctl start mysqld

Start mysql service.
$ service mysqld start

Secure Mysql server. (By default passwords are undefined.)
In order to make secure we need to set password of root and also block anonymous access.

$ mysql -u root password ‘new-password’

Now you will get the mysql prompt.
mysql>

Now we logged in to mysql

mysql> show databases;
+—————————-+
| Database                |
+—————————-+
| information_schema |
| mysql                     |
| test                       |
+—————————-+
3 rows in set (0.03 sec)

Output show by default mysql creates 3 databases.

Select ‘mysql’ database
mysql> use mysql

Show users & passwords
mysql> select user,host,password from user;
+——+———————–+————–+
| user | host                | password |
+——+———————–+————–+
| root | localhost          |               |
| root | test.test.com   |               |
| root | 127.0.0.1        |               |
|         | localhost          |              |
|         | test.test.com   |              |
+——+———————–+————-+
5 rows in set (0.00 sec)

Output shows 5 users but if you look in the ‘password’ field its blank means passwords are undefined.

Set Passwords.
mysql> set password for ‘root’@’test.test.com’= password (‘test’);
mysql> set password for ‘root’@’localhost’= password (‘test’);
mysql> set password for ‘root’@’127.0.0.1’= password (‘test’);

Verify Changes

mysql> select user,host,password from user;
+——+———————–+——————————————————————+
| user | host                | password                                                     |
+——+———————–+——————————————————————+
| root | localhost          | *xxxxxffccvv342432532wetegdsge1242132143a|
| root | test.test.com   | *xxxxxffccvv342432532wetegdsge1242132143a|
| root | 127.0.0.1        | *xxxxxffccvv342432532wetegdsge1242132143a|
|       | localhost          |                                                                    |
|       | test.test.com   |                                                                    |
+——+———————–+——————————————————————+
5 rows in set (0.00 sec)

Note : According to output there is still two Anonymous users exist without passwords.

Delete anonymous Users.
mysql> delete from mysql.user where user = ‘ ‘;
Query OK, 2 rows affected (0.00 sec)

Run ‘flush privileges’ command.
mysql>; flush privileges;
Query OK, 0 rows affected (0.00 sec)

Verify changes

+——+———————–+——————————————————————+
| user | host                | password                                                     |
+——+———————–+——————————————————————+
| root | localhost          | *xxxxxffccvv342432532wetegdsge1242132143a|
| root | test.test.com   | *xxxxxffccvv342432532wetegdsge1242132143a |
| root | 127.0.0.1        | *xxxxxffccvv342432532wetegdsge1242132143a |
+——+———————–+——————————————————————+
Now output shows we have 3 users and all secured with password.

Exit From MySql.

mysql> exit;

Start MySqld Service

$ service mysqld start

Please follow and like us:
0

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.