I had an episode when we tried to install the data directory mysql in a location other than the standard /var/lib location in our server. For that we uninstalled mysql several times but still some remnants were there elsewhere and it was interfering. If you need to re-install mysql just do the following.
1. yum erase mysql -> This will erase all your mysql from any location
2. yum install mysql-server -> This will again install mysql
3. login as root or as sudo run : service mysqld start -> This will start mysql
4. Create root password for your mysql using: mysqladmin -u root password lklklklskl -> This will reset root password as lklklklskl
5. If step 4 runs fine then all is well. But in my case it complained a lot about
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
I googled a lot and then found that in /etc/my.cnf file, mysql.sock file path is written. Inside my.cnf file I found the path was at /var/run/mysqld/mysqld.sock. Here notice it is mysqld.sock NOT mysql.sock. After a lot of caution I created a mysqld.sock link at /var/lib/mysql using:
ln -s /var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock
Then retired command 4 and it ran fine....
If your problem persists and it is unable to connect through mysql.sock file, then try connecting through TCP/IP. By default, mysql tries to connect to server via localhost that uses socket connector. But connecting to 127.0.0.1 uses TCP/IP connector. So, you can try connecting using:
mysql --protocol TCP -u xxx -p
or
If you sont want to create a symlink to mysqld.sock file, try giving the path to socket file with:
mysql --socket=/var/run/mysqld/mysqld.sock -u xxx -p
Alternatively, you can change the host name in /etc/my.cnf file to 127.0.0.1 from localhost. Then it will not look for socket connector.
1. yum erase mysql -> This will erase all your mysql from any location
2. yum install mysql-server -> This will again install mysql
3. login as root or as sudo run : service mysqld start -> This will start mysql
4. Create root password for your mysql using: mysqladmin -u root password lklklklskl -> This will reset root password as lklklklskl
5. If step 4 runs fine then all is well. But in my case it complained a lot about
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
I googled a lot and then found that in /etc/my.cnf file, mysql.sock file path is written. Inside my.cnf file I found the path was at /var/run/mysqld/mysqld.sock. Here notice it is mysqld.sock NOT mysql.sock. After a lot of caution I created a mysqld.sock link at /var/lib/mysql using:
ln -s /var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock
Then retired command 4 and it ran fine....
If your problem persists and it is unable to connect through mysql.sock file, then try connecting through TCP/IP. By default, mysql tries to connect to server via localhost that uses socket connector. But connecting to 127.0.0.1 uses TCP/IP connector. So, you can try connecting using:
mysql --protocol TCP -u xxx -p
or
If you sont want to create a symlink to mysqld.sock file, try giving the path to socket file with:
mysql --socket=/var/run/mysqld/mysqld.sock -u xxx -p
Alternatively, you can change the host name in /etc/my.cnf file to 127.0.0.1 from localhost. Then it will not look for socket connector.
No comments:
Post a Comment