MySQL Error:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

Solution:

STEP 1: login as root in terminal

[[email protected] ~]$ su
Password:

STEP 2: Start the mysqld

[[email protected] navayan]# /sbin/service mysqld start

You will get the following:

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 localhost 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 mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl

Please report any problem 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  ]

STEP 3: Now access the mysql prompt

[[email protected] navayan]# mysql -u root

You will get the following:

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

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

mysql>

STEP 4: Create the database

[[email protected] project_directory]# rake db:create

STEP 5: Migrate the database

[[email protected] project_directory]# rake db:migrate

STEP 6: Loading the database

[[email protected] project_directory]# rake db:fixtures:load

STEP 7: Test in browser

Now test your url http://localhost:3000 in a browser. It should run as expected!