Saturday 19 October 2013

How to Install MySQL Database Using Yum groupinstall on CentOS

In this article, let us review how to install MySQL on CentOS using yum. Instead of searching and installing mysql and related packages one-by-one, it is better to install MySQL using yum groups.

If you are interested in installing the full LAMP stack, refer to our earlier article on how to install/upgrade LAMP using yum.

1. Identify the Group name of MySQL Packages

yum grouplist displays all package groups that are available in the repository. As shown below, mysql package group is called “MySQL Database”.
# yum grouplist | grep -i mysql
   MySQL Database

2. What is bundled in the “MySQL Database” group?

yum groupinfo displays all the packages that are bundled in a group. This displays the mandatory, default and optional packages that are available in that particular group.
As shown below, “MySQL Database” group contains 1 mandatory package, 6 default packages, and 5 optional packages.
# yum groupinfo "MySQL Database"
Group: MySQL Database
 Description: This package group contains packages useful for use with MySQL.
 Mandatory Packages:
   mysql
 Default Packages:
   MySQL-python
   libdbi-dbd-mysql
   mysql-connector-odbc
   mysql-server
   perl-DBD-MySQL
   unixODBC
 Optional Packages:
   mod_auth_mysql
   mysql-bench
   mysql-devel
   php-mysql
   qt-MySQL

3. Install the “MySQL Database” group using yum groupinstall

yum groupinstall will install the “MySQL Database” group of packages as shown below.
# yum groupinstall "MySQL Database"

Resolving Dependencies
Dependencies Resolved

Transaction Summary
=========================
Install     12 Package(s)
Update       0 Package(s)
Remove       0 Package(s)         

Installed:
  MySQL-python.i386 0:1.2.1-1 libdbi-dbd-mysql.i386 0:0.8.1a-1.2.2
  mysql.i386 0:5.0.77-4.el5_4.2  mysql-connector-odbc.i386 0:3.51.26r1127-1.el5
  mysql-server.i386 0:5.0.77-4.el5_4.2  perl-DBD-MySQL.i386 0:3.0007-2.el5
  unixODBC.i386 0:2.2.11-7.1    

Dependency Installed:
  libdbi.i386 0:0.8.1-2.1 libdbi-drivers.i386 0:0.8.1a-1.2.2
  libtool-ltdl.i386 0:1.5.22-7.el5_4
  mx.i386 0:2.0.6-2.2.2 perl-DBI.i386 0:1.52-2.el5  

Complete!
Note: If you are having some issues during the installation, verify the full mysql install log to see what you are missing.

4. Verify MySQL Installation

Execute rpm -qa, to confirm that the mysql related packages are installed.
# rpm -qa | grep -i mysql
MySQL-python-1.2.1-1
mysql-5.0.77-4.el5_4.2
mysql-connector-odbc-3.51.26r1127-1.el5
mysql-server-5.0.77-4.el5_4.2
libdbi-dbd-mysql-0.8.1a-1.2.2
perl-DBD-MySQL-3.0007-2.el5
Check the /etc/passwd and /etc/group to make sure it has created a mysql username and group.
# grep mysql /etc/passwd
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

# grep mysql /etc/group
mysql:x:27:

5. MySQL Post installation – Execute mysql_install_db

mysql_install_db program will setup the necessary grant tables. The mysql_install_db program gets executed as part of the rpm installation. But, it doesn’t hurt to execute the mysql_install_db program again to make sure the grant tables are setup properly.
# /usr/bin/mysql_install_db --user=mysql
Installing MySQL system tables...OK
Filling help tables...OK
.....
The latest information about MySQL is available on the web at http://www.mysql.com

6. Start MySQL Server

# service mysqld status
mysqld is stopped

# service mysqld start
Starting MySQL:                                            [  OK  ]

7. Verify that the MySQL server is up and running.

# /usr/bin/mysqladmin version
/usr/bin/mysqladmin  Ver 8.41 Distrib 5.0.77, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version  5.0.77
Protocol version 10
Connection  Localhost via UNIX socket
UNIX socket  /var/lib/mysql/mysql.sock
Uptime:   39 sec

Threads: 1  Questions: 2  Slow queries: 0  Opens: 12  Flush tables: 1
Open tables: 6  Queries per second avg: 0.051
# /usr/bin/mysqlshow
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+

# /usr/bin/mysqlshow mysql
Database: mysql
+---------------------------+
|          Tables           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
Stop and start the mysql server again to make sure they are no issues.
# service mysqld stop
Stopping MySQL:                                            [  OK  ]

# service mysqld start
Starting MySQL:                                            [  OK  ]

8. Change the MySQL root account password

Change the MySQL root account password to something secure.
# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select host, user from mysql.user;
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root |
| localhost |      |
| localhost | root |
+-----------+------+
5 rows in set (0.00 sec)

mysql> set password for 'root'@'localhost' = PASSWORD('DoNotTell$AnyBody');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for 'root'@'127.0.0.1' = PASSWORD('DoNotTell$AnyBody');
Query OK, 0 rows affected (0.00 sec)
Make sure you are able to login to MySQL using the new password as shown below.
# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
 

 
 
Free counters!

Installing & Configuring MySQL Server

 http://centoshelp.org/servers/database/installing-configuring-mysql-server/

Installing & Configuring MySQL Server

This Howto will show you how to install MySQL 5.x, start the service, make sure the server starts on reboot, login via terminal, change the root database admin password, change the name of the root user, add a new user with specific privileges to a specific database, add a new DBA, add a new database, remove all anonymous logins, remove all non-root users, added file security steps, disable remote access (via port 3306), purge the scrollback history, and finally the installation of the gui tool mysql-administrator.

Applicable to Centos Versions:

  • Centos 5.x
  • Centos 6.x

Requirements

  1. Login to a terminal as root using one of these options: (su –login | su -l | or: su -)
  2. Yum and rpm must also be installed and functional (something is seriously wrong if they aren’t)

Doing the Work

  1. Install mysql mysql-server:
  2. # yum install mysql mysql-server
    Loading "priorities" plugin
    Loading "changelog" plugin
    Loading "fastestmirror" plugin
    Loading "allowdowngrade" plugin
    Loading "kernel-module" plugin
    Loading "fedorakmod" plugin
    Loading "installonlyn" plugin
    Loading "protectbase" plugin
    Setting up Install Process
    Setting up repositories
    livna                     100% |=========================| 1.1 kB    00:00
    updates                   100% |=========================| 1.2 kB    00:00
    core                      100% |=========================| 1.1 kB    00:00
    extras                    100% |=========================| 1.1 kB    00:00
    Loading mirror speeds from cached hostfile
    Reading repository metadata in from local files
    primary.xml.gz            100% |=========================| 1.8 MB    00:06     
    extras    : ################################################## 5594/5594
    0 packages excluded due to repository priority protections
    0 packages excluded due to repository protections
    Parsing package install arguments
    Resolving Dependencies
    --> Populating transaction set with selected packages. Please wait.
    ---> Downloading header for mysql to pack into transaction set.
    mysql-5.0.27-1.fc6.i386.r 100% |=========================|  36 kB    00:00
    ---> Package mysql.i386 0:5.0.27-1.fc6 set to be updated
    ---> Downloading header for mysql-server to pack into transaction set.
    mysql-server-5.0.27-1.fc6 100% |=========================|  33 kB    00:00
    ---> Package mysql-server.x86_64 0:5.0.27-1.fc6 set to be updated
    ---> Downloading header for mysql to pack into transaction set.
    mysql-5.0.27-1.fc6.x86_64 100% |=========================|  36 kB    00:00
    ---> Package mysql.x86_64 0:5.0.27-1.fc6 set to be updated
    --> Running transaction check
    --> Processing Dependency: perl-DBI for package: mysql-server
    --> Processing Dependency: perl(DBI) for package: mysql
    --> Processing Dependency: perl(DBI) for package: mysql-server
    --> Processing Dependency: perl-DBD-MySQL for package: mysql-server
    --> Restarting Dependency Resolution with new changes.
    --> Populating transaction set with selected packages. Please wait.
    ---> Downloading header for perl-DBI to pack into transaction set.
    perl-DBI-1.52-1.fc6.x86_6 100% |=========================|  16 kB    00:00
    ---> Package perl-DBI.x86_64 0:1.52-1.fc6 set to be updated
    ---> Downloading header for perl-DBD-MySQL to pack into transaction set.
    perl-DBD-MySQL-3.0007-1.f 100% |=========================| 8.5 kB    00:00
    ---> Package perl-DBD-MySQL.x86_64 0:3.0007-1.fc6 set to be updated
    --> Running transaction check
    
    Dependencies Resolved
    =============================================================================
    Package                 Arch       Version          Repository        Size
    =============================================================================
    Installing:
     mysql                   i386       5.0.27-1.fc6     updates           3.3 M
     mysql                   x86_64     5.0.27-1.fc6     updates           3.3 M
     mysql-server            x86_64     5.0.27-1.fc6     updates            10 M
    
    Installing for dependencies:
     perl-DBD-MySQL          x86_64     3.0007-1.fc6     core              147 k
     perl-DBI                x86_64     1.52-1.fc6       core              605 k
    
    Transaction Summary
    =============================================================================
    Install      5 Package(s)         
    Update       0 Package(s)         
    Remove       0 Package(s)         
    
    Total download size: 18 M
    Is this ok [y/N]:
  3. Start MySQL server daemon (mysqld):
  4. # chkconfig --level 2345 mysqld on; service mysqld start
    Initializing MySQL database:  Installing all prepared tables
    Fill help tables
    
    To start mysqld at boot time you have to copy support-files/mysql.server
    to the right place for your system
    
    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:
    /usr/bin/mysqladmin -u root password 'new-password'
    /usr/bin/mysqladmin -u root -h angstrom password 'new-password'
    See the manual for more instructions.
    
    You can start the MySQL daemon with:
    cd /usr ; /usr/bin/mysqld_safe &
    
    You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
    cd sql-bench ; perl run-all-tests
    
    Please report any problems with the /usr/bin/mysqlbug script!
    
    The latest information about MySQL is available on the web at
    
    http://www.mysql.com
    
    Support MySQL by buying support/licenses at http://shop.mysql.com
                                                               [  OK  ]
    Starting MySQL:                                            [  OK  ]
  5. Login as root database admin to MySQL server:
  6. # mysql -u root
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2 to server version: 5.0.27
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql>
  7. Delete ALL users who are not root:
  8. mysql> delete from mysql.user where not (host="localhost" and user="root");
    Query OK, 5 rows affected (0.15 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  9. Change root database admin password: (note: once this step is complete you’ll need to login with: mysql -p -u root)
  10. mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypass');
    
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  11. Change root username to something less guessable for higher security.
  12. mysql> update mysql.user set user="mydbadmin" where user="root";
    Query OK, 2 rows affected (0.00 sec)
    Rows matched: 2  Changed: 2  Warnings: 0
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  13. Remove anonymous access to the database(s):
  14. mysql> DELETE FROM mysql.user WHERE User = '';
    Query OK, 2 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  15. Add a new user with database admin privs for all databases:
  16. mysql> GRANT ALL PRIVILEGES ON *.* TO 'warren'@'localhost' IDENTIFIED BY 'mypass' WITH GRANT OPTION;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  17. Add a new user with database admin privs for a specific database, in this case the database is called “bugzilla”: (note: The ‘bugzilla’ database must first be added, see below.)
  18. mysql> GRANT ALL PRIVILEGES ON bugzilla.* TO 'warren'@'localhost' IDENTIFIED BY 'mypass';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    mysql> 
    
    Alternatively, you can give someone access to only certain privileges by substituting "ALL PRIVILEGES"
    with any combination of the following (commas included):
    SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES
  19. Add a MySQL database:
  20. mysql> create database bugzilla;
    Query OK, 1 row affected (0.15 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> quit
    Bye
  21. Installing mysql-administrator:
  22. The MySql Administrator packages for Centos 5.x can be found here:
    
    MySQL Administrator Packages:
    http://people.centos.org/hughesjr/mysql-gui-tools/i386/
    
    Possible Dependencies:
    http://centos.karan.org/el5/extras/testing/i386/RPMS/
    
    To install these packages download the desired tools into a directory on your desktop or a directory
    on the server, cd into the directory and issue this command: rpm -ivh *.rpm
    
    Make sure that the rpms you want to install are the only files in the directory.
  23. Improving local file security (after saving and exiting remember to: service mysqld restart for changes to take effect):
  24. The next change is to disable the use of LOAD DATA LOCAL INFILE command, which will help to 
    prevent against unauthorized reading from local files. This matters especially when new SQL
    Injection vulnerabilities in PHP applications are found.
    
    For that purpose, the following parameter should be added in the [mysqld] section in:
    /etc/my.cnf
    
    set-variable=local-infile=0
  25. Disabling remote access to the MySQL server (after saving and exiting remember to: service mysqld restart for changes to take effect).
  26. This change applies to the 3306/tcp port, on which MySQL listens by default. Because,
    according to the initial assumptions, the database will be used only by locally installed PHP
    applications, we can freely disable listening on that port. This will limit possibilities of
    attacking the MySQL database by direct TCP/IP connections from other hosts. Local communication
    will be still possible throw the mysql.sock socket. In order to disable listening on the
    mentioned port, the following parameter should be added to the [mysqld] section of /etc/my.cnf:
    
    skip-networking
    
    If, for some reason, remote access to the database is still required (e.g. to perform remote
    data backup), the SSH protocol can be used as follows:
    
    (modify to your needs)
    backuphost$ ssh mysqlserver /usr/local/mysql/bin/mysqldump -A > backup

Troubleshooting

How to test

  1. Make sure mysql and mysql server are indeed installed and that they are the correct versions:
  2. # rpm -qa | grep mysql && chkconfig --list | grep mysql
    mysql-5.0.27-1.fc6
    mysql-5.0.27-1.fc6
    mysql-gui-common-1.1.10-3.fc6
    mysql-server-5.0.27-1.fc6
    mysql-administrator-1.1.10-3.fc6
    mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
  3. Starting mysqld on boot:
  4. # chkconfig --level 2345 mysqld on && service mysqld restart && chkconfig --list | grep mysqld
    Stopping MySQL:                                            [  OK  ]
    Starting MySQL:                                            [  OK  ]
    mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
    
  5. Clear MySQL scrollback history (so sensitive data such as passwords cannot be seen by others with access):
  6. ]# cat /dev/null > ~/.mysql_history
  7. Show all users in the MySQL Server database:
  8. mysql> select * from mysql.user;
    8 rows in set (0.00 sec)
  9. Delete a user from the MySQL Server database:
  10. mysql> delete from mysql.user where host = "dev.mydomain.com";Query OK, 2 rows affected (0.00 sec)
  11. Delete a null user (user without a username) from the MySQL Server database:
  12. mysql> delete from mysql.user where user = ' ';
    Query OK, 1 rows affected (0.00 sec)

Common problems and fixes

Problem: User has not properly logged in with roots environment.
Fix: (switch to root with one of the following methods):
su –login
su -l
su -

More Information

Disclaimer

We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #centoshelp on irc.freenode.net
This has been tested on Centos 5.x and 6.x

Added Reading

Friday 18 October 2013

Howto Install MySQL on Linux

Reference link 2 :
http://www.thegeekstuff.com/2008/07/howto-install-mysql-on-linux/

Most of the Linux distro comes with MySQL.  If you want use MySQL, my recommendation is that you download the latest version of MySQL and install it yourself. Later you can upgrade it to the latest version when it becomes available. In this article, I will explain how to install the latest free community edition of MySQL on Linux platform.

1. Download the latest stable relase of MySQL

Download mySQL from mysql.com .  Please download the community edition of MySQL for your appropriate Linux platform. I downloaded the “Red Hat Enterprise Linux 5 RPM (x86)”. Make sure to download MySQL Server, Client and “Headers and libraries” from the download page.

  • MySQL-client-community-5.1.25-0.rhel5.i386.rpm
  • MySQL-server-community-5.1.25-0.rhel5.i386.rpm
  • MySQL-devel-community-5.1.25-0.rhel5.i386.rpm

2. Remove the existing default MySQL that came with the Linux distro

Do not perform this on an system where the MySQL database is getting used by some application.
[local-host]# rpm -qa | grep -i mysql
mysql-5.0.22-2.1.0.1
mysqlclient10-3.23.58-4.RHEL4.1

[local-host]# rpm -e mysql --nodeps
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
[local-host]# rpm -e mysqlclient10

3. Install the downloaded MySQL package

Install the MySQL Server and Client packages as shown below.
[local-host]# rpm -ivh MySQL-server-community-5.1.25-0.rhel5.i386.rpm MySQL-client-community-5.1.25-0.rhel5.i386.rpm
Preparing...                ########################################### [100%]
1:MySQL-client-community ########################################### [ 50%]
2:MySQL-server-community ########################################### [100%]
This will also display the following output and start the MySQL daemon automatically.
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h medica2 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/

Starting MySQL.[  OK  ]
Giving mysqld 2 seconds to start
Install the “Header and Libraries” that are part of the MySQL-devel packags
[local-host]# rpm -ivh MySQL-devel-community-5.1.25-0.rhel5.i386.rpm Preparing...                ########################################### [100%] 1:MySQL-devel-community  ########################################### [100%]
Note: When I was compiling PHP with MySQL option from source on the Linux system, it failed with the following error. Installing the MySQL-devel-community package fixed this problem in installing PHP from source.
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!

4.  Perform post-install security activities on MySQL.

At a bare minimum you should set a password for the root user as shown below:
[local-user]# /usr/bin/mysqladmin -u root password 'My2Secure$Password'
The best option is to run the mysql_secure_installation script that will take care of all the typical security related items on the MySQL as shown below. On a high level this does the following items:
  • Change the root password
  • Remove the anonymous user
  • Disallow root login from remote machines
  • Remove the default sample test database
[local-host]# /usr/bin/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] 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!

5.  Verify the MySQL installation:

You can check the MySQL installed version by performing mysql -V as shown below:
[local-host]# mysql -V
mysql  Ver 14.14 Distrib 5.1.25-rc, for redhat-linux-gnu (i686) using readline 5.1
Connect to the MySQL database using the root user and make sure the connection is successfull.
[local-host]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
Follows the steps below to stop and start MySQL

[local-host]# service mysql status
MySQL running (12588)                                      [  OK  ]
[local-host]# service mysql stop
Shutting down MySQL.                                       [  OK  ]
[local-host]# service mysql start
Starting MySQL.                                            [  OK  ]

Install MySQL for Database Server.

Reference link 1 :
http://www.server-world.info/en/note?os=CentOS_6&p=mysql

[root@www ~]#
yum -y install mysql-server
[root@www ~]#
/etc/rc.d/init.d/mysqld start

Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h www.server.world password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

Starting mysqld:     [  OK  ]

[root@www ~]#
chkconfig mysqld on

[root@www ~]#
mysql -u root
# connect to MySQL

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

# show user info

mysql>
select user,host,password from mysql.user;

# set root password

mysql>
set password for root@localhost=password('password');

Query OK, 0 rows affected (0.00 sec)
# set root password

mysql>
set password for root@'127.0.0.1'=password('password');

Query OK, 0 rows affected (0.00 sec)
# set root password

mysql>
set password for root@'www.server.world'=password('password');

Query OK, 0 rows affected (0.00 sec)
# delete anonymous user

mysql>
delete from mysql.user where user='';

Query OK, 2 rows affected (0.00 sec)
mysql>
select user,host,password from mysql.user;

mysql>
exit
# quit

Bye
[root@www ~]#
mysql -u root -p
# connect with root

Enter password:
# MySQL root password

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
exit

Bye

Tuesday 15 October 2013

RAID 0, RAID 1, RAID 2, RAID 3, RAID 4 RAID 5, RAID 6, RAID 10 Explained with Diagrams



RAID 0, RAID 1, RAID 2, RAID 3, RAID 4 RAID 5, RAID 6, RAID 10 Explained with Diagrams

by Ramesh Natarajan on August 10, 2010
RAID stands for Redundant Array of Inexpensive (Independent) Disks.
On most situations you will be using one of the following four levels of RAIDs.
  • RAID 0
  • RAID 1
  • RAID 5
  • RAID 10 (also known as RAID 1+0)
This article explains the main difference between these raid levels along with an easy to understand diagram.

In all the diagrams mentioned below:
  • A, B, C, D, E and F – represents blocks
  • p1, p2, and p3 – represents parity
RAID LEVEL 0
 

Following are the key points to remember for RAID level 0.
  • Minimum 2 disks.
  • Excellent performance ( as blocks are striped ).
  • No redundancy ( no mirror, no parity ).
  • Don’t use this for any critical system.


RAID LEVEL 1
 
Following are the key points to remember for RAID level 1.
  • Minimum 2 disks.
  • Good performance ( no striping. no parity ).
  • Excellent redundancy ( as blocks are mirrored )

RAID 2

  • This uses bit level striping. i.e Instead of striping the blocks across the disks, it stripes the bits across the disks.
  • In the above diagram b1, b2, b3 are bits. E1, E2, E3 are error correction codes.
  • You need two groups of disks. One group of disks are used to write the data, another group is used to write the error correction codes.
  • This uses Hamming error correction code (ECC), and stores this information in the redundancy disks.
  • When data is written to the disks, it calculates the ECC code for the data on the fly, and stripes the data bits to the data-disks, and writes the ECC code to the redundancy disks.
  • When data is read from the disks, it also reads the corresponding ECC code from the redundancy disks, and checks whether the data is consistent. If required, it makes appropriate corrections on the fly.
  • This uses lot of disks and can be configured in different disk configuration. Some valid configurations are 1) 10 disks for data and 4 disks for ECC 2) 4 disks for data and 3 disks for ECC
  • This is not used anymore. This is expensive and implementing it in a RAID controller is complex, and ECC is redundant now-a-days, as the hard disk themselves can do this.




RAID 3

  • This uses byte level striping. i.e Instead of striping the blocks across the disks, it stripes the bits across the disks.
  • In the above diagram B1, B2, B3 are bytes. p1, p2, p3 are parities.
  • Uses multiple data disks, and a dedicated disk to store parity.
  • The disks have to spin in sync to get to the data.
  • Sequential read and write will have good performance.
  • Random read and write will have worst performance.
  • This is not commonly used.









RAID 4

  • This uses block level striping.
  • In the above diagram B1, B2, B3 are blocks. p1, p2, p3 are parities.
  • Uses multiple data disks, and a dedicated disk to store parity.
  • Minimum of 3 disks (2 disks for data and 1 for parity)
  • Good random reads, as the data blocks are striped.
  • Bad random writes, as for every write, it has to write to the single parity disk.
  • It is somewhat similar to RAID 3 and 5, but little different.
  • This is just like RAID 3 in having the dedicated parity disk, but this stripes blocks.
  • This is just like RAID 5 in striping the blocks across the data disks, but this has only one parity disk.
  • This is not commonly used







RAID LEVEL 5


Following are the key points to remember for RAID level 5.
  • Minimum 3 disks.
  • Good performance ( as blocks are striped ).
  • Good redundancy ( distributed parity ).
  • Best cost effective option providing both performance and redundancy. Use this for DB that is heavily read oriented. Write operations will be slow.


 

 

 

 

 

 

RAID 6


 
  • Just like RAID 5, this does block level striping. However, it uses dual parity.
  • In the above diagram A, B, C are blocks. p1, p2, p3 are parities.
  • This creates two parity blocks for each data block.
  • Can handle two disk failure
  • This RAID configuration is complex to implement in a RAID controller, as it has to calculate two parity data for each data block.









RAID LEVEL 10

Following are the key points to remember for RAID level 10.
  • Minimum 4 disks.
  • This is also called as “stripe of mirrors”
  • Excellent redundancy ( as blocks are mirrored )
  • Excellent performance ( as blocks are striped )
  • If you can afford the dollar, this is the BEST option for any mission critical applications (especially databases).


RAID 10 Vs RAID 01 (RAID 1+0 Vs RAID 0+1) Explained with Diagram
by Ramesh Natarajan on October 24, 2011
RAID 10 is not the same as RAID 01.
This article explains the difference between the two with a simple diagram.
I’m going to keep this explanation very simple for you to understand the basic concepts well. In the following diagrams A, B, C, D, E and F represents blocks.

RAID 10

  • RAID 10 is also called as RAID 1+0
  • It is also called as “stripe of mirrors”
  • It requires minimum of 4 disks
  • To understand this better, group the disks in pair of two (for mirror). For example, if you have a total of 6 disks in RAID 10, there will be three groups–Group 1, Group 2, Group 3 as shown in the above diagram.
  • Within the group, the data is mirrored. In the above example, Disk 1 and Disk 2 belongs to Group 1. The data on Disk 1 will be exactly same as the data on Disk 2. So, block A written on Disk 1 will be mirroed on Disk 2. Block B written on Disk 3 will be mirrored on Disk 4.
  • Across the group, the data is striped. i.e Block A is written to Group 1, Block B is written to Group 2, Block C is written to Group 3.
  • This is why it is called “stripe of mirrors”. i.e the disks within the group are mirrored. But, the groups themselves are striped.
If you are new to this, make sure you understand how RAID 0, RAID 1 and RAID 5 and RAID 2, RAID 3, RAID 4, RAID 6 works.



RAID 01

  • RAID 01 is also called as RAID 0+1
  • It is also called as “mirror of stripes”
  • It requires minimum of 3 disks. But in most cases this will be implemented as minimum of 4 disks.
  • To understand this better, create two groups. For example, if you have total of 6 disks, create two groups with 3 disks each as shown below. In the above example, Group 1 has 3 disks and Group 2 has 3 disks.
  • Within the group, the data is striped. i.e In the Group 1 which contains three disks, the 1st block will be written to 1st disk, 2nd block to 2nd disk, and the 3rd block to 3rd disk. So, block A is written to Disk 1, block B to Disk 2, block C to Disk 3.
  • Across the group, the data is mirrored. i.e The Group 1 and Group 2 will look exactly the same. i.e Disk 1 is mirrored to Disk 4, Disk 2 to Disk 5, Disk 3 to Disk 6.
  • This is why it is called “mirror of stripes”. i.e the disks within the groups are striped. But, the groups are mirrored.
Main difference between RAID 10 vs RAID 01
  • Performance on both RAID 10 and RAID 01 will be the same.
  • The storage capacity on these will be the same.
  • The main difference is the fault tolerance level. On most implememntations of RAID controllers, RAID 01 fault tolerance is less. On RAID 01, since we have only two groups of RAID 0, if two drives (one in each group) fails, the entire RAID 01 will fail. In the above RAID 01 diagram, if Disk 1 and Disk 4 fails, both the groups will be down. So, the whole RAID 01 will fail.
  • RAID 10 fault tolerance is more. On RAID 10, since there are many groups (as the individual group is only two disks), even if three disks fails (one in each group), the RAID 10 is still functional. In the above RAID 10 example, even if Disk 1, Disk 3, Disk 5 fails, the RAID 10 will still be functional.
  • So, given a choice between RAID 10 and RAID 01, always choose RAID 10.