# "Can't connect to local MySQL server "... Why?????

## cgmd

Hi, all...

I've been struggling with a new install of mysql. It goes something like this...  I emerged mysql-4.0.25-r2, and near the end of the emerge received instructions to run:

```
ebuild /var/db/pkg/dev-db/mysql-4.0.25-r2/mysql-4.0.25-r2.ebuild config
```

I was required to make a root password, but the server start-up failed: 

```
.050923 20:41:00 Can't start server : Bind on unix socket: Address already in use

050923 20:41:00 Do you already have another mysqld server running on socket: //var/run/mysqld/mysqld.sock ?

050923 20:41:00 Aborting

050923 20:41:00 //usr/sbin/mysqld: Shutdown Complete

....ERROR 2002: Can't connect to local MySQL server through socket '//var/run/mysqld/mysqld.sock' (111)

cat: //var/run/mysqld/mysqld.pid: No such file or directory

kill: usage: kill [-s sigspec | -n signum | -sigspec] [pid | job]... or kill -l [sigspec]

```

Repeated attempts to start the server fail as follows: 

```
# mysql -u root -p

Enter password:

ERROR 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

```

The mysql daemon starts, but with a mesage that the mysql server is not running: 

```
 # /etc/init.d/mysql start

 * Starting mysqld (/etc/mysql/my.cnf) ...

..... * MySQL NOT started, proceding anyway                                                                          [ ok ]

```

The files /var/run/mysqld/mysqld.sock and /var/run/mysqld/mysqld.pid do not exist, and this seems to be part of the problem.  :Sad: 

I sure could use some expert advice with this!!

Thanks, in advance, for any help!!

----------

## electrofreak

have you tried:

```
/etc/init.d/mysql stop && killall mysqld && /etc/init.d/mysql zap && /etc/init.d/mysqld start
```

zap resets it to think it is actually stopped. killall obviously just ensures it really is stopped.

----------

## cgmd

electrofreak...

Thank you for the suggestion...  I tried your suggested command, but it appears to have failed:

```
cgmd # /etc/init.d/mysql stop && killall mysqld && /etc/init.d/mysql zap && /etc/init.d/mysqld start

 * Stopping mysqld (/etc/mysql/my.cnf) ...        !
```

If I reboot my system and then try to start mysql I get: 

```
cgmd # /etc/init.d/mysql start

 * Starting mysqld (/etc/mysql/my.cnf) ...

..... * MySQL NOT started, proceding anyway                                                                                   [ ok ]

```

But... Why is MySQL not being started??

Anyone with thoughts about this???

Thanks...

----------

## cgmd

I have now spent 1 1/2 days struggling with this... I've read the forums, the HowTo's, and the Google stuff... Nothing really fits, and I continue with the same proglem.   :Crying or Very sad: 

Can't anyone help me with this???

Thanks...

----------

## Decibels

Have seen something similar before, just don't remember the fix. Think it was something with owner:group on

/var/lib/mysql folders.  Check yours, mine are all:   mysql:mysql

Plus, you have to have a default 'mysql' database there for it to work. When it installs and you create the initial database you will have a mysql & test databases.  The mysql one has to be there, that is where it saves the users, passwords, permissions,....

----------

## cgmd

Decibels wrote:

 *Quote:*   

> Think it was something with owner:group on
> 
> /var/lib/mysql folders. Check yours, mine are all: mysql:mysql 

 

Thanks for commenting! Mine too are set to mysql:mysql.

I likewise have both test and mysql directories within /var/log/mysql...

Most of my problem with starting MySQL seems to center around the /var/run/mysqld directory where I have no mysqld.sock or mysqld,pid file. I'm curious as to whether these two files should be present when the MySQL server is not running? Or do those two files appear only when MySQL starts??

Could someone please give me infirmation about the mysqld.sock and mysqld.pid files, and why I may not have them?

Thanks to anyone who can shed some light on this!   :Smile: 

----------

## Decibels

No, if you stop mysql neither is in /var/run/mysqld. As soon as you start them they appear.

Have you checked /etc/mysql/my.cnf to make sure it is not screwed up and is pointing to 

```
pid-file        = /var/run/mysqld/mysqld.pid

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

Assume it is correct cause of your comments, but might be a good idea to check my.cnf still.

*Notice you say you don't have the pid or sock files, but, you do have the /var/run/mysqld folder though right? If not create it.

**Oh, well, guess that is a moot point, see you posted you did that in another post.

----------

## cgmd

Decibels wrote:

 *Quote:*   

> Have you checked /etc/mysql/my.cnf to make sure it is not screwed up and is pointing to
> 
> Code:
> 
> pid-file        = /var/run/mysqld/mysqld.pid
> ...

 

My my.cnf seems ok:

```
[mysqld]

user            = mysql

pid-file        = /var/run/mysqld/mysqld.pid

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

log-error       = /var/log/mysql/mysqld.err

```

Possibly this MySQL problem is related to this is another thread I'm using with regard to dev-lang/php-5.0.5-r1: https://forums.gentoo.org/viewtopic-t-384780-highlight-.html

I'm wondering if this issue might be related to the sockets flag discussed in that thread?   :Confused: 

Any thoughts?

Thanks...

----------

## Decibels

I'll look at the thread. Noticed another one that corrected not being able to connect with etc-update. 

You've probably already did all yours though.

Not sure, I don't have php installed, when checked the USE Flags it had '-sockets'. Why is yours showing +sockets?

If so, it is beyond me why it would cause a problem.

----------

## cgmd

I believe I added +sockets to /etc/make.conf when I was following PHP HowTo.

This was, perhaps, after emerging PHP, and I probably didn't add the flag correctly. 

Much of this is new to me, and I'm not not sure what to try next...  :Confused: 

----------

## Decibels

Have you by chance looked at this post: https://forums.gentoo.org/viewtopic-t-334048-highlight-mysql+socket.html

Also, reading somewhere else, said you might want to check your bind-address (last post):

https://forums.gentoo.org/viewtopic.php?p=1842932#1842932

Here is my /etc/mysql/my.cnf incase you want to check defaults:

```
# /etc/mysql/my.cnf: The global mysql configuration file.

# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql/files/my.cnf-4.0.14-r1,v 1.2 2004/07/18 02:47:43 dragonheart Exp $

#

# This file can be simultaneously placed in three places:

# 1. /etc/mysql/my.cnf to set global options.

# 2. /var/lib/mysql/my.cnf to set server-specific options.

# 3. ~/.my.cnf to set user-specific options.

#

# One can use all long options that the program supports.

# Run the program with --help to get a list of them.

#

# The following values assume you have at least 32M RAM!

[client]

#password       = my_password

port            = 3306

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

[safe_mysqld]

err-log         = /var/log/mysql/mysql.err

[mysqld]

skip-innodb

user            = mysql

pid-file        = /var/run/mysqld/mysqld.pid

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

log-error       = /var/log/mysql/mysqld.err

# If set, mysql logs all queries(general query log). This will be deprecated in

# 5.0. This logs all queries, even error queries and is slow.

# log          = /var/log/mysql/mysql.log

#

# If you really need logging, use rather binary logging. Especially when doing

# replication. Read

# file:/usr/share/doc/mysql-*/manual.html.gz#Replication

# You can use PURGE MASTER LOGS TO '$hostname-bin.010' to get rid of old logs

# from $hostname-bin.01 up to $hostname-bin.09 while the slave server is

# running.

# Before doing that, check which logfile slave curently uses by running

# mysql> SHOW SLAVE STATUS

# To list logfiles on master do:

# mysql> SHOW MASTER LOGS

# Then use PURGE for those not needed anymore only! Never remove the files

# manually!

#

# Also consult RESET MASTER and RESET SLAVE commands before doing any changes

# mysql> RESET MASTER - Deletes all binary logs listed in the index

#                       file, resetting the binlog index file to be empty.

# mysql> RESET SLAVE - Makes the slave forget its replication position in

#                      the master logs.

# mysql> SET SQL_LOG_BIN=0  - this turns off logging (execute on MASTER only)

# mysql> SET SQL_LOG_BIN=1  - this turns on logging (execute on MASTER only)

#

# log-bin

# set-variable  = binlog-do-db=non_existant

# set-variable  = binlog-ignore-db=database_name

#

# server-id has to unique for each master or slave in your network,

# lets use last number from IP address

# server-id      = 207

basedir         = /usr

datadir         = /var/lib/mysql

tmpdir          = /tmp

language        = /usr/share/mysql/english

skip-locking

set-variable    = key_buffer=16M

set-variable    = max_allowed_packet=1M

set-variable    = thread_stack=128K

# keep secure by default!

bind-address    = 127.0.0.1

port            = 3306

# this can make it even more secure:

#skip-networking

[mysqldump]

quick

set-variable    = max_allowed_packet=1M

[mysql]

#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]

set-variable    = key_buffer=16M

```

----------

## cgmd

Decibels...

Thanks for sharing your /etc/mysql/my.cnf!! My problem was at this location:

```
[mysqld]

skip-innodb 
```

This was commented out, and my problem was as shown in the mysqld log: 

```
^G/usr/sbin/mysqld: Can't create/write to file '/tmp/ibl9EiMv' (Errcode: 13)

050925 11:29:24  InnoDB: Error: unable to create temporary file; errno: 13

050925 11:29:24 Can't init databases

050925 11:29:24 Aborting

```

Uncommenting "skip-innodb" allows mysql to start as expected!!   :Very Happy: 

Naturally, my next question... What is InnoDB, and do I, for any reason, need it??   :Confused: 

Thank you, Decibels, for helping me work through this!

----------

## Decibels

Glad to help!

Trying to remember now if that is a default my.cnf file or I added that!? Remember something about not wanting or using or trouble with InnoDB. 

Looking here: http://lugatgt.org/articles/sec_mysql/ though seems that skip-innodb should have been in the default my.cnf uncommented like it is. 

Anyway, do remember that didn't want/need it for my Stock App wrote in Python. Think would be more use for a multiuser/large DB. I am certainly no expert though by far.

As far as what it is. Here is a good link:

http://mysqld.active-venture.com/InnoDB_overview.html

Index

Seems that you either have to give some configuration for InnoDB or use the skip-innodb.

----------

## cgmd

Great follow-up info! I obviously don't need InnoDB, either, and can only wonder why the default my.cnf had it commented out!

Thanks, again...

----------

## seigen

FYI in my case the key seemed to be

chown mysql /var/run/mysqld

I think some other forums suggested permissions, and when someone mentioned those files I just checked to see who owned the directory and it was root.  It seemed appropriate for that directory to be owned by mysql instead.

Of course I haven't actually used the database for anything yet, but it did start...

----------

## cgmd

siegen wrote: *Quote:*   

> FYI in my case the key seemed to be
> 
> chown mysql /var/run/mysqld 

 

I had tried that suggestion, but without benefit. I didn't get mysql to work till: *Quote:*   

> Uncommenting "skip-innodb" allows mysql to start as expected:

 

...This was mentioned above...   :Smile: 

----------

