Tuesday, May 18, 2010

MySQL - Troubleshooting - Can’t connect to local MySQL server through socket /tmp/mysql.sock

Yesterday is a big trouble and very urgent. Do not know why, the are conflict in processing when my previous version for mysql is still running and cannot being kill. It conflict in --port=3306 so the website cannot find the socket.

0:01.14 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --log-error=/usr/local/mysql/data/mdce1corpsvr03.xxx.com.my.err --pid-file=/usr/local/mysql/data/mdce1corpsvr03.xxx.com.my.pid --socket=/var/mysql/mysql.sock --port=3306


I detect it when check it out :

ps xa | grep mysql

ps -aef | grep mysql

the we can check it using:

netstat -ln | grep mysql

What I am doing yesterday is:

kill - 9 PIDNo - cannot
kill -15 PIDNo - the server restarted

so no others choice.

1. first and important - BACKUP the database first!!! and copy in /users/admin folder

mysqldump -p [db name] > [backup.dmp]
 
2. remove the previous version that disturbing the process

sudo rm -rf /usr/local/mysql*

3. install new version of mysql
4. relink the socket

sudo ln -s /var/mysql/mysql.sock /tmp/mysql.sock


5. create and restore the database using mysqldump

mysql> CREATE database xxxxa;
mysql -u #username# -p #xxxxa# < #backup.dmp#

6. set password for -u root

$ mysqladmin -u root password NEWPASSWORD

7. change database name at dbconnect.php



Refering to  :

Info
mysqld, also known as MySQL Server, is the main program that does most of the work in a MySQL installation.

The mysqld program has many options that can be specified at startup. For a complete list of options, run this command:

shell> mysqld --verbose --help 

When connecting to a MySQL server located on the local system, the mysql client connects thorugh a local file called a socket instead of connecting to the localhost loopback address 127.0.0.1. For the mysql client, the default location of this socket file is /tmp/mysql.sock.
 
Link :
http://dev.mysql.com/doc/refman/5.1/en/mysqld.html
http://www.tech-recipes.com/rx/762/solve-cant-connect-to-local-mysql-server-through-socket-tmpmysqlsock/

Uninstalling MySQL on Mac OS X Leopard

To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:
  • Use mysqldump to backup your databases to text files!
  • Stop the database server
  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
  • rm -rf ~/Library/PreferencePanes/My*
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
The last two lines are particularly important as otherwise, you can't install an older version of MySQL even though you think that you've completely deleted the newer version!

Link :

http://akrabat.com/computing/uninstalling-mysql-on-mac-os-x-leopard/
http://obscuredclarity.blogspot.com/2009/08/uninstall-mysql-on-mac-os-x.html

Unix Post-Installation Procedures

Link :  http://dev.mysql.com/doc/refman/5.1/en/unix-post-installation.html


Starting and Troubleshooting the MySQL Server

Link : http://dev.mysql.com/doc/refman/5.1/en/starting-server.html


How to Protect or Change the MySQL Unix Socket File

Link : http://dev.mysql.com/doc/refman/5.1/en/problems-with-mysql-sock.html - I am not trying this yet.

No comments:

Post a Comment