Jul 29, 2012

J2EE Design Patterns and their relationships


Jul 19, 2012

Installing mysql on Red Hat

To install mysql on linux, we need RPM files. You can download MySQL-5.5.20-1.linux2.6.i386.tar from mysql download page to understand and try steps from this article.

For standard installation, one needs to install two RPMs: Server and Client. Server RPM contains mysql database, services, daemons etc whereas Client RPM contains admin tools, querying tools etc.

In MySQL-5.5.20-1.linux2.6.i386.tar file, you will get following required RPMs

MySQL-server-5.5.20-1.linux2.6.i386.rpm
MySQL-client-5.5.20-1.linux2.6.i386.rpm

In my machine, I have downloaded RPMs on in /bin folder. Now go to shell and change directory to bin.

[root@mysql bin]# rpm -ivf MySQL-server-5.5.20-1.linux2.6.i386.rpm

This will install server RMPs without setting password for root user causing anonymous access. To change the password you will need mysqladmin. It is bundled in client RPM.

[root@mysql bin]# rpm -ivf MySQL-client-5.5.20-1.linux2.6.i386.rpm

After successful installation run following command to change root password

[root@mysql bin]# /usr/bin/mysqladmin -u root password 'new-password'

Now your mysql is ready to run. But the moment you try to connect it will give error like " is not allowed to connect to mysql service"

The issue is caused because of default privileges given to root user. You need connect privilege to connect from a remote machine. You can grant all privileges to root user.

[root@mysql bin]# su - mysql

This will open bash for mysql user created when you install server RPMs.

-bash-3.2$ 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.5.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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>

mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '';
Query OK, 0 rows affected (0.00 sec)


Now try connecting the mysql server, you should be able to connect.

For unlucky people like me :), things do not start easily. When I tried installing mysql for the first time, mysqld service could not start. If the same thing happens to you, first check your installed packages using following command

[root@mysql bin]# rpm -qa | grep 'MySQL'
MySQL-server-5.5.20-1.linux2.6
MySQL-client-5.5.20-1.linux2.6

If you can see both RPM, you are okay with installation or nothing has been uninstalled. If it does not show you both, you need to install the required RPM.

Second step is to find mysqld and provide privilege using

[root@mysql bin]# chmod 775 mysqld

and then

[root@mysql bin]# service mysqld start

You can also start it using

[root@mysql bin]# /usr/bin/mysqld_safe &

That's it. There can be a lot of difference in issues faced while installing. Linux requires a thorogh understanding of how different flavour of linux works. But as programmers we can use google to stay away from that burden.

You can share your experiences here if you wish to.