# mysql trouble, no mysqld.sock

## Rojahon

This is my first attempt at installing MySQL and I managed to get it started but when I entered the command

```
mysqladmin -u root password ********
```

I got 

```
mysqladmin: connect to server at 'localhost' failed

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

Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

```

I checked the directory (/var/run/mysqld/) and there are no files in it at all.  I don't think that is a good thing.  I tried reemerging it but still no files.  Anyone know what's up?  Is there a place I can download just the files for that directory?

----------

## ter_roshak

If you do a netstat -a --inet command, do you see mysql listening?  Also, have you tried connecting without entering a password?

----------

## dryadcito

Since you are trying mysql for the first time, I'll remind you that you must run 

1. mysql_install_db   before running it the first time 

2. "/etc/init.d/mysql start" to start the DBMS. What messages are shown when you try this from the console?

----------

## Rojahon

 *ter_roshak wrote:*   

> If you do a netstat -a --inet command, do you see mysql listening?  Also, have you tried connecting without entering a password?

 

No, I did not see anything that said mysql

 *dryadcito wrote:*   

> Since you are trying mysql for the first time, I'll remind you that you must run 
> 
> 1. mysql_install_db   before running it the first time 
> 
> 2. "/etc/init.d/mysql start" to start the DBMS. What messages are shown when you try this from the console?

 

I've been following http://gentoo-wiki.com/HOWTO_Setup_MythTV#MySQL so I have already done that.  I don't remember exactly what it said when I did mysql_install_db but it was successful.  I can do it again if it wont hurt anything.  When I did (/etc/init.d/mysql start) it came out as [ok].

----------

## ter_roshak

Well, if you did not see anything that said mysql in your 'netstat -a --inet' output, your mysql instance is not running.  Is there any information in the /var/log/mysql logs?

----------

## Rojahon

I unemerged and then reemerged and same thing.  Here's what's in the log since I reemerged.  The rest is all the same.

```
050506 19:50:27  mysqld started

050506 19:50:27 Can't start server: Bind on TCP/IP port: Cannot assign requested address

050506 19:50:27 Do you already have another mysqld server running on port: 3306 ?

050506 19:50:27 Aborting

050506 19:50:27 /usr/sbin/mysqld: Shutdown Complete

050506 19:50:27  mysqld ended

```

EDIT:  that's in mysql.err  The only thing in mysqld.err is (050506 19:49:35 /usr/sbin/mysqld: Shutdown Complete) and there is nothing in mysql.log

----------

## adaptr

Please run and post output of the following:

```
ps fax | grep mysql

netstat -ltp | grep mysql
```

----------

## Rojahon

for (ps fax | grep mysql)

```

14802 pts/1    S+     0:00                              \_ grep mysql

```

and nothing was outputted by (netstat -ltp | grep mysql)

----------

## moocha

This seems to be the clue for the main culprit:

```
050506 19:50:27 Can't start server: Bind on TCP/IP port: Cannot assign requested address
```

Did you forcibly bind mysqld to a specific address other than 127.0.0.1? What is the output of

```
grep grep bind /etc/mysql/my.cnf
```

?

----------

## Rojahon

well (grep grep bind /etc/mysql/my.cnf) didn't work but I figured you ment (grep bind /etc/mysql/my.cnf)

The output was

```

bind-address    = 24.243.***.***

```

----------

## moocha

 *Rojahon wrote:*   

> well (grep grep bind /etc/mysql/my.cnf) didn't work but I figured you ment (grep bind /etc/mysql/my.cnf)

 Oops. Of course. *Rojahon wrote:*   

> The output was
> 
> ```
> 
> bind-address    = 24.243.***.***
> ...

 That IP address must match your IP address. If it doesn't, you'll get the error you just got and MySQL will fail to start. This can be a problem for hosts receiving their external IP address via DHCP since it may change, and then my.cnf will be out of date.

If you don't need external hosts to be able to connect to your server, don't bind to the external IP. Bind to 127.0.0.1.

If you really intend to allow connections from the outside world to your MySQL server and are on DHCP, you probably will need to let mysqld bind to all interfaces. To do this, comment out the bind-address directive in my.cnf and (re)start the server.

----------

## Rojahon

Now that you mention it, I really think I only need to have it accessable from within my computer.  I'll bind it to 127.0.0.1 and see what happens

----------

## Rojahon

No it still gives me the same error when I try to do (mysqladmin -u root password ********).  No one has yet to address the fact that my (/var/run/mysqld/) directory is empty.

----------

## moocha

OK, this is odd.

Did you perchance compile the kernel without support for UNIX sockets?

----------

## Rojahon

I change my mind though.  It does need to be accessible to the outside world.  Sorry about that.

----------

## moocha

 *Rojahon wrote:*   

> I change my mind though.  It does need to be accessible to the outside world.  Sorry about that.

 That's OK, but you need to make sure my.cnf contains the correct, current IP address every time mysqld is started. *moocha wrote:*   

> Did you perchance compile the kernel without support for UNIX sockets?

 Well, did you? To check, look for CONFIG_UNIX in your kernel's .config file. If you're not sure what I'm talking about, try this command:

```
zgrep CONFIG_UNIX /proc/config.gz
```

It must report something along the lines of

```
CONFIG_UNIX=y
```

(ignore the other lines a la CONFIG_UNIX98_PTS, they're irrelevant for this). It's not OK to have CONFIG_UNIX=m (UNIX socket support as a module). All sort of weird things happen in that scenario.

----------

## Rojahon

Sorry I'm fairly new to linux(gentoo), and my friend pretty much installed it for me.

My my.cnf does contain the correct ip address

and the command indeed returns CONFIG_UNIX=y

----------

## moocha

To quote Mr. Carroll, "Curiouser and curiouser!", cried Alice.

I'm stumped for the moment. Will get back if I find another lead.

----------

## adaptr

Okay, to recap:

- first make sure there are no left-over mysql services:

```
/etc/init.d/mysql zap
```

- then check that my.cnf contains at least the following:

```
[client]

port = 3306

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

[mysqld]

bind-address = 0.0.0.0

port = 3306

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

#skip-networking

```

Make double sure that skip-networking is commented out, and the value for the socket is exactly the same in both cases.

Now try starting it up again:

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

Barring any errors, re-run the commands I gave you earlier.

If that still fails, consider unmerging and then remerging mysql, paying very close attention to all USE flags and dependencies.

----------

## Rojahon

Well it still failed.  I already have unemerged and reemerged once and it still failed.  Are there any USE flags that have to do with my problem?  Can't I just include them in the emerge command?

----------

## Rojahon

Okay I unemerged and am reemerging.  I've been watching it for a little while and I haven't seen anything about any USE flags.  I did notice that mysql is the only dependancy.  When watching it I did manage to notice some warnings.  They may be nothing serious but here's a pieces:

```

/usr/share/aclocal/libast.m4:403: warning: underquoted definition of AST_STATUS

/usr/share/aclocal/libast.m4:429: warning: underquoted definition of dps_snprintf_oflo      w

/usr/share/aclocal/libast.m4:466: warning: underquoted definition of dps_vsnprintf_ofl      ow

/usr/share/aclocal/libast.m4:512: warning: underquoted definition of dps_symlink_open_      bug

/usr/share/aclocal/libast.m4:586: warning: underquoted definition of dps_rlimit_nproc

/usr/share/aclocal/libast.m4:634: warning: underquoted definition of dps_rlimit_memloc      k

/usr/share/aclocal/libart.m4:11: warning: underquoted definition of AM_PATH_LIBART

/usr/share/aclocal/libIDL.m4:6: warning: underquoted definition of AM_PATH_LIBIDL

/usr/share/aclocal/imlib.m4:9: warning: underquoted definition of AM_PATH_IMLIB

/usr/share/aclocal/imlib.m4:167: warning: underquoted definition of AM_PATH_GDK_IMLIB

/usr/share/aclocal/gtk.m4:7: warning: underquoted definition of AM_PATH_GTK

/usr/share/aclocal/glib.m4:8: warning: underquoted definition of AM_PATH_GLIB

/usr/share/aclocal/freetype2.m4:7: warning: underquoted definition of AC_CHECK_FT2

/usr/share/aclocal/audiofile.m4:12: warning: underquoted definition of AM_PATH_AUDIOFI      LE

/usr/share/aclocal/ao.m4:9: warning: underquoted definition of XIPH_PATH_AO

/usr/share/aclocal/ORBit.m4:4: warning: underquoted definition of AM_PATH_ORBIT

autoheader-2.59: WARNING: Using auxiliary files such as `acconfig.h', `config.h.bot'

autoheader-2.59: WARNING: and `config.h.top', to define templates for `config.h.in'

autoheader-2.59: WARNING: is deprecated and discouraged.

autoheader-2.59: 

autoheader-2.59: WARNING: Using the third argument of `AC_DEFINE' and

autoheader-2.59: WARNING: `AC_DEFINE_UNQUOTED' allows to define a template without

autoheader-2.59: WARNING: `acconfig.h':

autoheader-2.59: 

autoheader-2.59: WARNING:   AC_DEFINE([NEED_FUNC_MAIN], 1,

autoheader-2.59:                [Define if a function `main' is needed.])

autoheader-2.59: 

autoheader-2.59: WARNING: More sophisticated templates can also be produced, see the

autoheader-2.59: WARNING: documentation.

```

```

/usr/share/aclocal/libgcrypt.m4:23: warning: underquoted definition of AM_PATH_LIBGCRYPT

/usr/share/aclocal/libast.m4:11: warning: underquoted definition of AST_CHECK_LIBAST

/usr/share/aclocal/libast.m4:72: warning: underquoted definition of AST_SIZE_TYPE

/usr/share/aclocal/libast.m4:89: warning: underquoted definition of AST_REGEXP_SUPPORT

/usr/share/aclocal/libast.m4:153: warning: underquoted definition of AST_X11_SUPPORT

/usr/share/aclocal/libast.m4:183: warning: underquoted definition of AST_IMLIB2_SUPPORT

/usr/share/aclocal/libast.m4:219: warning: underquoted definition of AST_MMX_SUPPORT

/usr/share/aclocal/libast.m4:243: warning: underquoted definition of AST_STD_CHECKS

/usr/share/aclocal/libast.m4:279: warning: underquoted definition of AST_PROG_CHECKS

/usr/share/aclocal/libast.m4:291: warning: underquoted definition of AST_VAR_CHECKS

/usr/share/aclocal/libast.m4:311: warning: underquoted definition of AST_HEADER_CHECKS

/usr/share/aclocal/libast.m4:318: warning: underquoted definition of AST_FUNC_CHECKS

/usr/share/aclocal/libast.m4:328: warning: underquoted definition of AST_TYPE_CHECKS

/usr/share/aclocal/libast.m4:339: warning: underquoted definition of AST_ARG_DEBUG

/usr/share/aclocal/libast.m4:360: warning: underquoted definition of AST_ARG_REGEXP

/usr/share/aclocal/libast.m4:368: warning: underquoted definition of AST_ARG_BACKQUOTE_EXEC

/usr/share/aclocal/libast.m4:391: warning: underquoted definition of AST_FLAGS

/usr/share/aclocal/libast.m4:403: warning: underquoted definition of AST_STATUS

/usr/share/aclocal/libast.m4:429: warning: underquoted definition of dps_snprintf_oflow

/usr/share/aclocal/libast.m4:466: warning: underquoted definition of dps_vsnprintf_oflow

/usr/share/aclocal/libast.m4:512: warning: underquoted definition of dps_symlink_open_bug

/usr/share/aclocal/libast.m4:586: warning: underquoted definition of dps_rlimit_nproc

/usr/share/aclocal/libast.m4:634: warning: underquoted definition of dps_rlimit_memlock

/usr/share/aclocal/libart.m4:11: warning: underquoted definition of AM_PATH_LIBART

/usr/share/aclocal/libIDL.m4:6: warning: underquoted definition of AM_PATH_LIBIDL

/usr/share/aclocal/imlib.m4:9: warning: underquoted definition of AM_PATH_IMLIB

/usr/share/aclocal/imlib.m4:167: warning: underquoted definition of AM_PATH_GDK_IMLIB

/usr/share/aclocal/gtk.m4:7: warning: underquoted definition of AM_PATH_GTK

/usr/share/aclocal/glib.m4:8: warning: underquoted definition of AM_PATH_GLIB

/usr/share/aclocal/freetype2.m4:7: warning: underquoted definition of AC_CHECK_FT2

/usr/share/aclocal/audiofile.m4:12: warning: underquoted definition of AM_PATH_AUDIOFILE

/usr/share/aclocal/ao.m4:9: warning: underquoted definition of XIPH_PATH_AO

/usr/share/aclocal/ORBit.m4:4: warning: underquoted definition of AM_PATH_ORBIT

```

I didn't manage to catch any warnings about the (/var/run/mysqld/) directory.

----------

## moocha

Those warnings are harmless - they're caused by outdated aclocal macros provided by other packages. Can't possibly have anything to do with this issue.

----------

## Rojahon

Is there a way someone could zip the files in their (/var/run/mysqld/) directory?  Then I could just manualy put the files there.  Or would that not help?

----------

## moocha

No. A socket may look like a file, but it isn't a file. You could conceivably tar up a socket then untar it somewhere else, but you wouldn't be able to connect to that "socket file" since it will belong to nobody in particular, least of all a running MySQL daemon.

----------

## adaptr

You should take those steps more slowly, and one at a time.

Also check permissions on the mysql daemons, the /var/run/mysqld directory, and try increasing the log level.

----------

## Rojahon

What steps should I take more slowly?

I don't know where the daemons are and I don't know how to change the log lvl.

The permissions on /var/run/mysqld are (drwxr-xr-x)

----------

## adaptr

The steps I and others in this thread have mentioned more than once in the preceding 2 dozen posts.

Let me spell it out:

1. unmerge and CLEAN mysql completely, also deleting the startup scripts form /etc/init.d

2. delete every last trace of the previous installation, including /var/lib/mysql and /var/log/mysql

3. run emerge -av mysql and take note of exactly what it says

4. now emerge it and watch closely for any errors (read the emerge log afterwards)

5. edit my.cnf to make sure the file is as advised: bind-address = 0.0.0.0 and skip-networking commented out (or deleted)

6. now run the mysql database install script

7. start mysql from the init script

If you stil have problems after these steps you should probably file a bug.

----------

## Rojahon

I guess I'm filing a bug.

----------

## Rojahon

I found this

http://bugs.mysql.com/bug.php?id=8513

someone else has already posted a bug report.  They said they had a fix for it but I couldn't make sense of it  :Embarassed:  .

----------

## Rojahon

I have no idea what happened but I did something and I guess it worked.  I managed to login.  I did "netstat -ltp | grep mysql" again and for the first time it outputted something:

```
tcp        0      0 *:mysql                 *:*                     LISTEN      973/mysqld
```

I should be able to handle it from here.  Thx for your help.

----------

## adaptr

So you did... what ?

What did you do ?

----------

## Rojahon

That's the thing, I didn't do anything.  It just kind of worked when I tried it.  I messed around with the fix they had in that bug report but everything I did came up with an error.  Apparently though it did something because now those files are in the /var/run/mysqld/ directory and I am able to start up mysql.

BTW:  You don't happen to know how to view the contents of a database do you?  I don't feel like getting Apache and phpMyadmin set up.  Thx again for your time

----------

## adaptr

Log on to mysql:

```
mysql -p
```

Then enter any of the following:

```
mysql> show databases; (show all databases)

mysql> use <databasename>; (select a database)

mysql> show tables; (show tables in the database)

mysql> describe <tablename> (show the table structure)

mysql> select * from <tablename>; (list table contents)
```

Obviously, phpMyAdmin is preferable  :Wink: 

----------

## Rojahon

Thx a lot.  I've been using SQL for longer than I have linux.  I'd rather not fool around with setting up apache, for right now at least.  Not after this little ordeal.

Thx again

----------

## DukeofMilan

I've been having the same troubles getting MySQL to run under a new Gentoo installation - I've followed all of the above steps several times, but still to no avail. I looked at the bug request mentioned, and the suggested fix was thus:

```
Suggested fix:

I've put a quick fix into mysqld_safe to create /var/run/mysqld if it doesn't

exist. Since I'm quite new to MySQL you'll probably have a better way.

*** /usr/bin/mysqld_safe.0      2005-02-14 19:24:29.000000000 -0800

--- /usr/bin/mysqld_safe        2005-02-14 19:40:46.000000000 -0800

***************

*** 149,154 ****

--- 149,163 ----

  parse_arguments PICK-ARGS-FROM-ARGV "$@"

 

safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-/var/run/mysqld/mysql

d.sock}}

+ # Create directory the $mysql_unix_port is in.

+ unix_port_dir=`dirname $safe_mysql_unix_port`

+ if [ ! -d $unix_port_dir ]

+ then

+   mkdir $unix_port_dir

+   chmod 775 $unix_port_dir

+   chown "${user}.${user}" $unix_port_dir

+ fi

+

  if test ! -x $ledir/$MYSQLD

  then

    echo "The file $ledir/$MYSQLD doesn't exist or is not executable"
```

I have no idea how to implement that, if it is something even possible in the situation - any help with that, or with a simpler solution for getting MySQL to run (I only need it locally, this machine is strictly networkless, MySQL's primary use will be with Apache 1.3.33 and PHP 5.0, or PHP 5 CLI) would be greatly appreciated.

----------

## dave77034

This seems to be the same issue I and few others in the Other Things Gentoo forum are seeing.  The owner on /var/run/mysql is incorrectly defaulting to root:mysql.

Here's what I'm seeing:

 *dave77034 wrote:*   

> 
> 
> I can't say when or what started this (recent emerge -u, I guess) but mysql started having similar problems at boot.
> 
> I noticed that /var/run/mysqld has root:mysql as the owner/group. A default install of mysql has the run user as mysql. I chown -R mysql:mysql /var/run/mysqld, then /etc/init.d/mysql zap, /etc/init.d/mysql start and everything worked fine. Until I rebooted to see if it comes up at boot.
> ...

 

Hope that helps someone here explain why the owner of /var/run/mysql is changing to root.

----------

