Tag Archives: MySQL 5.5

[MySQL] Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

아래 나온 소스코드 http://localhost/testconnection.php 를 실행했을 때
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
의 에러 메시지가 출력된 경우,
=>
/etc/my.cnf 파일 안에 socket 값을 다음처럼 설정하고

socket  = /var/run/mysqld/mysqld.sock

mysql 서버를 재실행하고
다시 http://localhost/testconnection.php 를 접속하면
mysql 서버 접속이 성공함

> sudo vim /var/www/testconnection.php

<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

> sudo vim /etc/my.cnf

...
# The following options will be passed to all MySQL clients
[client]
#password       = your_password
#socket         = /tmp/mysql.sock
socket          = /var/run/mysqld/mysqld.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
#socket         = /tmp/mysql.sock
socket          = /var/run/mysqld/mysqld.sock
 ...
 

[MySQL 5.5] To install and use a MySQL binary distribution

Installing MySQL from Generic Binaries on Unix/Linux
다운로드: http://dev.mysql.com/downloads/mysql/#downloads
Linux – Generic 2.6 (x86, 64-bit), Compressed TAR Archive:
(mysql-5.5.16-linux2.6-x86_64.tar.gz)

참조: A step by step guide to upgrading to MySQL 5.5:

http://www.ovaistariq.net/490/a-step-by-step-guide-to-upgrading-to-mysql-5-5/

To install and use a MySQL binary distribution, the basic command
sequence looks like this:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db –user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe –user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysqld