How to install mysql in linux with practical

 

Summary

In the previous tutorial we have learned about the introductionof mysql and advantages of mysql . In this article we will learn how to install mysql in linux operating system like centos ,oracle,redhat and ubuntu.

Prerequisite

To install mysql in linux system first we need to have a system with linux operating system. Now you can disable selinux as per your requirement and then configure yum repository to install mysql package from centralized yum repository. By default  mysql runs on port no 3306. You can configure firewall on linux system as per your requirement.

Install mysql in linux

Now we have configured yum repository. First we need to verify that whether mysql server package is installed or not on the server using the below command.

#rpm –qa mysql*

If package is installed on the server you will get the output and you have nothing to do. If this package is not installed the server you need to install mysql package using you repository. Upto linux version 6.x mysql package is available in the yum repository . After 6.x or 7.x onward we can use mysql repository to install mysql server package.

To search mysql package it is available or not and which version will be available we can execute the below command.

#yum provides mysql*

Note:  Mysql* means we can get all mysql related package from the yum repository.

 To install mysql server in linux system(rhel,centos,oracle)  we need to execute the below command.

#yum install mysql-server

How to install mysql in linux
How to install mysql in linux


Start mysql service in linux

After installation of mysql server we need to start the service and check the service status  using the below commands.

[root@mysqldailytasks ~]# service mysqld start

Starting mysqld:                                           [  OK  ]

[root@mysqldailytasks ~]# service mysqld status

mysqld (pid  1547) is running...


To enable mysqld service at the startup mode i.e After reboot the physical server mysqld service will be automatically using the below command.

 

#chkconfig mysqld on

 

How to secure and set mysql root password

After completion above all steps we need to secure mysql root password using the below command.

 [root@mysqldailytasks ~]# mysql_secure_installation 


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

 

In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):

OK, successfully used password, moving on...

 

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

 

You already have a root password set, so you can safely answer 'n'.

 

Change the root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

 ... Success!

 

 

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] n

 ... skipping.

 

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] n

 ... skipping.

 

By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] n

 ... skipping.

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] y

 ... Success!

 

Cleaning up...

 

 

 

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

 

Thanks for using MySQL!



How to connect mysql server from linux terminal

To connect mysql server from linux shell we need to execute the below command.

Mysql –u root –p

Enter password:


Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.1.71 Source distribution

 

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> 


Check mysql version

To check mysql version we can execute the below query in mysql promt.

mysql> select version();

+-----------+

| version() |

+-----------+

| 5.1.71    |

+-----------+

1 row in set (0.00 sec)

  

Conclusion

 In this article we have learned  how to install mysql in linux operating system like centos ,oracle,redhat and ubuntu,how to start the mysql service,how to secure root password for mysql,how to connect mysql from linux shell and finally how to check version of mysql server.

SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment