# MySQL installation problems

## Myth|384

Hello fellow gentooists,

I am trying to install MySQL on my server, I use this wiki as a guide:

http://gentoo-wiki.com/HOWTO_Apache2_with_PHP_MySQL

After I have emerged MySQL, I use the following command to install the database:

```
/usr/bin/mysql_install_db
```

No error messages are shown.

Next I do:

```
bash-2.05b# /etc/init.d/mysql start

 * Starting mysqld...                                                     [ ok ]
```

The problem shows up with the next command:

```
bash-2.05b# /usr/bin/mysql -u root

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

/var/run/mysqld is empty

I have searched the Gentoo forum thouroughly. I tried different approaches discribed in various solutions, which did not work for me.

I also used the following command instead of the mysql_install_db script.

```
ebuild /var/db/pkg/dev-db/mysql.*/mysql.*.ebuild config
```

Any thoughts?

----------

## expat_iain

One springs to mind, su to the user that mysqld runs as. Then try to cd into the directory where the socket file is created and touch <filename>.

I'm guessing there's a permissions issue with the mysqld user creating that file.

Regs.

Iain.

----------

## Myth|384

Thanks for the quick reply.

As I said the /var/run/mysqld folder is empty, so there is not much te be touched...

----------

## dashnu

who owns /var/run/mysqld ?

should look like this 

```
drwxr-xr-x  2 mysql      mysql 4096 Jan 24 12:57 mysqld
```

```
chown mysql:mysql /var/run/mysqld
```

than start mysql

----------

## Myth|384

User and group of /var/run/mysqld are already set to mysql.

----------

## dashnu

try ?

```
mysql -u root -p mysql
```

----------

## Myth|384

As root:

```
bash-2.05b# mysql -u root -p mysql

Enter password:

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

 :Sad: 

----------

## expat_iain

 *Myth|384 wrote:*   

> As I said the /var/run/mysqld folder is empty, so there is not much te be touched...

 

Okay, but if you cannot cd into that directory from / as the mysqld user, then the sock file will not be created. Can you start mpsqld from shell as root and connect okay?? That's one thing to try that the server will start. Next up, can you try and touch a file (any name) into /var/run/mysqld  as the mysql user. If it's done and it works, at least we can cross that one off the list. Very often it's these sorts of things that hold the problem!

Regs.

Iain.

----------

## Myth|384

As root:

```
bash-2.05b# /etc/init.d/mysql start

 * Starting mysqld...                                                     [ ok ]
```

```
bash-2.05b# ps a | grep mysql

12395 pts/1    S+     0:00 grep mysql

```

So it looks like MySQL isn't running at all...

----------

## PhragMunkee

I'm getting the same errors--no socket errors and no instances of mysqld running in ps -ax.  I'm sure our issues are related.  No amount of my.cnf files and mysqld_safe --datadir=/var/lib/mysql seem to work.

One clue is from the /var/log/mysqld.err file:

```
050201  1:24:04 /usr/sbin/mysqld: Can't find file: './mysql/host.frm' (errno: 13)

050201  1:24:04 Fatal error: Can't open privilege tables: Can't find file: './mysql/host.frm' (errno: 13)

050201  1:24:04 Aborting

050201  1:24:04 /usr/sbin/mysqld: Shutdown Complete
```

This appears several times over and over again (from failed attempts to start).  However, that directory and those .frm files exist!

```
root@www mysql # ls -l /var/lib/mysql/mysql

total 66

-rw-rw----  1 mysql mysql    0 Jan 27 14:50 columns_priv.MYD

-rw-rw----  1 mysql mysql 1024 Jan 27 14:50 columns_priv.MYI

-rw-rw----  1 mysql mysql 8778 Jan 27 14:50 columns_priv.frm

-rw-rw----  1 mysql mysql  306 Jan 27 14:50 db.MYD

-rw-rw----  1 mysql mysql 3072 Jan 27 14:50 db.MYI

-rw-rw----  1 mysql mysql 9088 Jan 27 14:50 db.frm

-rw-rw----  1 mysql mysql    0 Jan 27 14:50 func.MYD

-rw-rw----  1 mysql mysql 1024 Jan 27 14:50 func.MYI

-rw-rw----  1 mysql mysql 8641 Jan 27 14:50 func.frm

-rw-rw----  1 mysql mysql    0 Jan 27 14:50 host.MYD

-rw-rw----  1 mysql mysql 1024 Jan 27 14:50 host.MYI

-rw-rw----  1 mysql mysql 9064 Jan 27 14:50 host.frm

-rw-rw----  1 mysql mysql    0 Jan 27 14:50 tables_priv.MYD

-rw-rw----  1 mysql mysql 1024 Jan 27 14:50 tables_priv.MYI

-rw-rw----  1 mysql mysql 8877 Jan 27 14:50 tables_priv.frm

-rw-rw----  1 mysql mysql  240 Jan 31 02:56 user.MYD

-rw-rw----  1 mysql mysql 2048 Jan 31 02:57 user.MYI

-rw-rw----  1 mysql mysql 9806 Jan 27 14:50 user.frm
```

Oh, and before I forget, a "uname -a" returns

```
root@www mysql # uname -a

Linux www 2.6.8.1-co-0.6.2-pre6 #58 Sun Oct 24 21:48:46 IST 2004 i686 AMD Athlon(tm) XP 3000+ AuthenticAMD GNU/Linux
```

It's a coLinux install, but I don't believe that has much of anything to do with the errors as it does maybe the portage compile/fubared scripts?

An "emerge dev-db/mysql --pretend --verbose" returns:

```
root@www mysql # emerge dev-db/mysql --pretend --verbose

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[ebuild   R   ] dev-db/mysql-4.0.22-r2  +berkdb -debug -innodb +perl +readline (-selinux) +ssl -static +tcpd 0 kB

Total size of downloads: 0 kB
```

The 0 kB is because it's already been downloaded and attempted to compile/install.

I've worked on this for two nights now and haven't made any progress (even tried unmerging and re-merging).

----------

## kashani

I'd do the following

```

/etc/init.d/mysql stop

/etc/init.d/mysql zap

emerge -C mysql

rm -rf /var/lib/mysql

rm /etc/mysql/my.conf

rm /var/run/mysql/*

emerge mysql

```

Ideally things would be pretty clean at this point. 

```

azul root # /etc/init.d/mysql start

 * You don't appear to have the mysql database installed yet.

 * Please run /usr/bin/mysql_install_db to have this done...

```

so far so good

```

azul root # /usr/bin/mysql_install_db

Preparing db table

Preparing host table

Preparing user table

Preparing func table

Preparing tables_priv table

Preparing columns_priv table

Installing all prepared tables

To start mysqld at boot time you have to copy support-files/mysql.server

to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/etc/init.d/mysql start (you have to start the server first!)

/usr/bin/mysqladmin -u root -h azul password 'new-password'

/usr/bin/mysqladmin -u root password 'new-password'

```

now to set the password using the last line as because be default mysql does not run on the hostname's IP, only localhost.

```

azul root # /etc/init.d/mysql start  

 * Starting mysqld...                                                         [ ok ]

azul root # /usr/bin/mysqladmin -u root password 'db-passwd'

azul root # mysql -u root -pdb-passwd

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3 to server version: 4.0.22

```

Hopefully that works and you're all set.

kashani

----------

## PhragMunkee

That seemed to do the trick!  The only thing you suggested differently was:

```
rm -rf /var/lib/mysql 

rm /etc/mysql/my.conf 

rm /var/run/mysql/*
```

Very much appreciated!  I hope it also helps out with Myth|384!

Thanks again!

----------

## Myth|384

Hmmm, doesn't work for me...   :Crying or Very sad: 

All goes well until:

```
bash-2.05b# /usr/bin/mysqladmin -u root password 'myPassword'

/usr/bin/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 will try it one more time...

----------

## kashani

I'd guess that mysql isn't running. 

1. check your system logs

2. check your mysql logs

3. think about your cflags. Mysql can be very sensitive to how you built it.

kashani

----------

## Dwin

Mmmmh, I am not a specialist but, is your loopback correctly configured ?

Do you have some firewall that could block the port 3306 ?

What's the value of the parameter bind-address in your /etc/mysql/my.cnf ?

----------

## Myth|384

...   :Confused: Last edited by Myth|384 on Wed Feb 09, 2005 1:03 pm; edited 1 time in total

----------

## gnostek

OK, I installed mySQL-4.0.22-r2 during my installation of slashcode, and everything worked perfectly.  Slash was broken though  :Sad:  , tried reinstalling slash... complained about DBI.  Decided to reinstall mySQL, and have received

```
root@gnosys gnostek # /usr/bin/mysqladmin -u root password 'mypassword'

/usr/bin/mysqladmin: connect to server at 'localhost' failed

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

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

root@gnosys gnostek # /usr/bin/mysqladmin -u root -h gnosys password 'mypassword'

/usr/bin/mysqladmin: connect to server at 'gnosys' failed

error: 'Access denied for user: 'root@localhost' (Using password: NO)'
```

ever since.  I have tried several variations on kashani's fix, and am still getting the same set of error messages  :Confused:  i'm going to hunt through log files now... any further suggestions?

----------

## Myth|384

...  :Twisted Evil: Last edited by Myth|384 on Thu Feb 10, 2005 11:09 am; edited 1 time in total

----------

## gnostek

```
bash # killall mysqld

bash # rm /var/lib/init.d/started/mysql*

bash # /etc/init.d/mysql start

bash # mysql -u root
```

This fix from #gentoo-servers gave me that glorious 'mysql>' prompt which I have been craving... hope it helps.  Now, off to break it again....  :Laughing: 

----------

## Myth|384

Ok, kashani, I got it almost working now. I followed your guide again, but instead of:

```
/usr/bin/mysql_install_db
```

I have to do:

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

Next:

```
bash-2.05b# /etc/init.d/mysql start 

 * Starting mysqld...                                                         [ ok ]

bash-2.05b# /usr/bin/mysqladmin -u root password 'db-passwd'

bash-2.05b# mysql -u root -p
```

Filling in the correct password gives a mysql> prompt.

Checking if processes are running:

```
bash-2.05b# ps -A | grep mysql

 7540 ?        00:00:00 mysqld_safe

 7576 ?        00:00:00 mysqld

 7577 ?        00:00:00 mysqld

 7578 ?        00:00:00 mysqld

 7579 ?        00:00:00 mysqld
```

Looks fine to me.

Pid and sock files are both created:

```
bash-2.05b# ls /var/run/mysqld

mysqld.pid  mysqld.sock
```

After I add mysql to the default or boot run level, I reboot the system and try to start mysql again;

```
bash-2.05b# mysql -u root -p

Enter password:

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

Man what a troubles...   :Confused: 

(Sorry for reposting this message after gnostek's messages, but else it may look as if this subtject is solved.)

----------

## stealthy

Ok just my two cents.

I had the exact same problem. I think it originally started or maybe not...

anyway I had the exact same errors.

but by doing 

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

and then restarting it by 

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

fixed up everything...didn't have to re-emerge or anything

 :Smile: 

----------

## Myth|384

No... That does not work for me.

Anyway, is it that hard to solve this problem?  :Confused: 

----------

