MySQL database server Installation, Configuration in Linux

MySQL database server Installation, Configuration in Linux

by -
0 1376

MySQL Database Points

This tutorial explain about MySQL database running on a Linux server. This tutorial will make you understand how to install and setup MySQL database server and how to use basic MySQL queries/command, which initially we use in MySQL database.

  • Introduction and use of Database
  • Installation and Configuration
  • To Login and exit from Database
  • Data types explain
  • Database Storage engines

A brief Introduction about MySQL database

What is Database?

A database is a collection of information so that it can easily be accessed, managed, and updated.

What is MySQL Database?

MySQL is an open source database management software that helps user to store, organize, and retrieve data. MySQL offers great reliability and easy to use and maintain the record in DB. Purpose of using database is to get rid the manual task into diary or other documentary. MySQL, pronounced either “My S-Q-L” or “My Sequel,” It is based on the structure query language (SQL). Standard MySQL commands, such as ADD, DROP, INSERT, and UPDATE can be used.

Install and Configure MySQL Database Server in CentOS/RHEL

Install MySQL package in Centos/RHEL/5 & 6 distribution

Install the MySQL server package through the CentOS/RHEL repository.

[[email protected] ~]#yum install mysql mysql-server

Start Mysql Service.

[[email protected] ~]# service mysqld restart

Check MySQL service status

[[email protected] ~]# service mysqld status

Permanently on MySQL service on startup

[[email protected] ~]# chkconfig mysqld on 

Identify on which ports MySQL work.

[[email protected] ~]# netstat -tunlp | grep mysqldtcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1657/mysqld

Setup MySQL root user password

To create root password for first time, use mysqladmin command at shell prompt as follows:

[[email protected] ~]# mysqladmin -u root password [newpasswordhere]

Example;

[[email protected] ~]# mysqladmin -u root password [email protected]

Change/reset MySQL root password

[[email protected] ~]#mysqladmin -u root -p[oldpassword] password [newpass]

Example;

[[email protected] ~]#mysqladmin -u root [email protected] password [email protected]

Setup MySQL database using mysql_secure_installation command

Alternatively, you can run the below command mysql_secure_installation from the Linux root user, to complete the fields that make sense for your MySQL configuration.

We recommend that you configure the following secure settings:

  • Set a password for the MySQL root user.
  • Remove MySQL anonymous users.
  • Disallow remote login for the MySQL root user.
  • The MySQL root user is allowed to connect to the database, but only from the local host.
  • Remove the test database.
  • Reload the Privileges table.

 [[email protected] ~]# /usr/bin/mysql_secure_installation

output;

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):       (type password here if you already generate root password or hit enter if not )

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] y

… Success!

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] y

… Success!

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] y

– Dropping test database…

… Success!

– Removing privileges on test database…

… Success!

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!

Login into MySQL Database

Login in to MySQL database as root user

[[email protected] ~]# mysql -u root –p

Password: *******

output;

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

Your MySQL connection id is 17

Server version: 5.1.73 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 respectiveowners.

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

mysql>

Exit from MySQL database

mysql> exit;

Bye

[[email protected] ~]#

Note: After settings the mysql root password from bash sehll, clear the password  history from  .bash_history file

Shell/bash command history saved in

[[email protected] ~]# vim .bash_history

MySQL database queryhistory saved in

[[email protected] ~]# vim .mysql_history

MySQL Data type reference

Numeric Data Types

TinyInt – A very small integer with a signed range of -128 to 127 and an unsigned range of 0 to 255 .

SmallInt – A small integer with a signed range of -32768 to 32767 and an unsigned range of 0 to 65535 .

MediumInt– A medium sized integer with a signed range of -8388608 to 8388607 and an unsigned range of 0 to 16777215 .

Int (Integer) – It can store 0 to 255 characters.  holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis.

Bigint–  A large integer with a signed range of -9223372036854775808 to 9223372036854775807 and an unsigned range of 0 to 18446744073709551615.

String/text Datatype

VARCHAR(size) –It Holds a variable length string (letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters.

CHAR(size) – Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters

Date and Time data type

DATE     YYYY-MM-DD

DATETIME  YYYY-MM-DD HH:MM:SS

TIMESTAMP   YYYYMMDDHHMMSS

TIME  HH:MM:SS

Database Storage engines

MySQL provides support for different storage engines which act as varying table type handlers. Two most common storage engines are MyISAM and InnoDB. Most of the time, the default storage engine as defined by the store_engine option in the MySQL config file is typically MyISAM.

  • MyISAM
  • InnoDB
  • MERGE
  • MEMORY (HEAP)
  • ARCHIVE
  • CSV

 Differents between MyISAM and InnoDB.

MyISAM – This manages non transactional tables, provides high-speed storage and retrieval, supports full text searching.

InnoDB –It provides transaction-safe (ACID compliant) tables, supports FOREIGN KEY referential-integrity constraints. It supports commit, rollback, and crash-recovery capabilities to protect data.

This is all about basic concept of MySQL database server to perform some administration task, later we will post some useful MySQL command in our next tutorial.

Download PDF

CEO, KV IT-Solutions Pvt. Ltd. | [email protected] | 9810028374|
Linux Professional and an Industrial Trainer | 20 + years Experience in IT Industry

” We are born free, No Gate and Windows can snatch our freedom “

SIMILAR ARTICLES

0 1700

0 1355

0 1218

NO COMMENTS

Leave a Reply