[MySQL] Install difficulties : Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock'

Ryan Schmidt ryandesign at macports.org
Mon Mar 31 04:18:53 PDT 2008


On Mar 31, 2008, at 05:45, sourceforge.rocks at xemaps.com wrote:

> I've installed and reinstalled MySQL with the following command line:
>     $ sudo port install mysql5 +server
>
> Initially, I had trouble creating the initial mysql database  
> because the /opt/local/temp directory did not exist (and therefore  
> the /opt/local/temp/mysql5 directory did not exist).
>
> Creating these two directories, and making the mysql user the owner  
> of /opt/local/temp/mysql5 allowed me to build the initial database,  
> but sadly it had no data in any of the non-index tables.

Where are you getting "/opt/local/temp" from? I've never heard of  
that directory. Unless you've modified your my.cnf (in /opt/local/etc/ 
mysql5/my.cnf or /etc/my.cnf or any of several other locations) and  
deliberately pointed it at /opt/local/temp, your databases should be  
stored in /opt/local/var/db/mysql5. Did you run mysql_install_db to  
install the initial tables?


> I went ahead and unistalled mysql5 and reinstalled it, and now I  
> get the following when I try to change the root password:
>     $ mysqladmin -u root password 'newpass'
>     mysqladmin: connect to server at 'localhost' failed    error:  
> 'Can't connect to local MySQL server through socket '/opt/local/var/ 
> run/mysql5/mysqld.sock' (2)'    Check that mysqld is running and  
> that the socket: '/opt/local/var/run/mysql5/mysqld.sock' exists!
>
> I verified that mysqld is running through the Activity Monitor.
>
> Sure enough, /opt/local/var/run/mysql5/mysqld.sock does not exist.   
> In fact, mysqld.sock does not exist anywhere on my hard drive, a  
> fact which I determined by:
>     $ sudo find / -name "*.sock"

If mysqld is running, there should be a socket somewhere so that you  
can connect to the running server. Have you modified your my.cnf to  
tell it to put the socket somewhere else? If so, look there. The  
default location for the socket file in MacPorts mysql5 is /opt/local/ 
var/run/mysql5. The default location for Apple and mysql.com binary  
packages used to be /tmp but this was found to be an insecure  
location. I believe it was changed to /var/mysql.


> Elsewhere, I found an instruction to
>     $ touch opt/local/var/run/mysql5/mysqld.sock
>
> This command creates an empty file of the correct name; however,  
> when I tried to change the root password, I got:
>     $ mysqladmin -u root password 'newpass'
>     mysqladmin: connect to server at 'localhost' failed
>     error: 'Can't connect to local MySQL server through socket '/ 
> opt/local/var/run/mysql5/mysqld.sock' (38)'    Check that mysqld is  
> running and that the socket: '/opt/local/var/run/mysql5/ 
> mysqld.sock' exists!
>
> Note that only the error number changed.

Where did you find that instruction? I don't think it's helpful...  
There's no need to touch the socket file... mysqld creates it when  
the server is running.

Does mysqld have permission to write to the /opt/local/var/run/mysql5  
directory? (Is it owned by the mysql user and group?) Does it have  
permission to write to your database directory?


> When I stopped and restarted mysql5:
>     $ sudo launchctl unload /Library/LaunchDaemons/ 
> org.macports.mysql5.plist
>     $ sudo launchctl load -w /Library/LaunchDaemons/ 
> org.macports.mysql5.plist
> I found that the mysqld.sock was deleted from opt/local/var/run/ 
> mysql5/

I'm not surprised that it would delete the socket file when stopping  
the server; that's probably what it's supposed to do.


> Does anyone have any ideas about what I'm supposed to do to get a  
> properly functioning MySQL5 installation?
>
> Environment:
>     MacPorts version 1.600.  I've done a selfupdate before  
> attempting to install MySQL5
>     Power Mac G4
>     Mac OS X 10.4.11

It should mostly "just work", and it does for me. I have 10.4.11 on  
Intel.

Can you check if there's anything in the log file in your database  
directory? If the server had trouble starting (and therefore didn't  
create the socket), the log should say why.



More information about the macports-users mailing list