# FreeBSD Jail mysql connecting problems



## praxis (Mar 19, 2012)

I'm using mysql in a jail and I am having problems importing my sql backups.

When *I* run:

```
mysql  -u root -p -h localhost cncrepair < cncrepair_2012_03_08_1.sql
```
I get the following error:

```
Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
```

However, I can log into to the mysql deamon just fine with: 

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

The root user has full privileges over the 'cncrepair' database.  The mysql website (http://dev.mysql.com/doc/refman/5.1/en/access-denied.html) suggests that maybe there is an incorrect option file.  However, I have not set up any of the template/default .cnf files.

I ended up compressing the sql file and using phpmyadmin to do the initial import but I would still like to know what's causing the error.


----------



## SirDice (Mar 19, 2012)

There is no localhost inside a jail. You need to connect to the jail's IP address. You also need to make sure MySQL is bound to only the jail's IP address.


----------



## praxis (Mar 19, 2012)

What exactly should the jails /etc/hosts file look like?  This is what i have:

```
::1,,...,...localhost localhost.my.domain
 14 127.0.0.1,..,...localhost localhost.my.domain
 15 192.168.1.160,..,...localhost localhost.my.domain apache
```

I also created a /usr/local/etc/mysql/my.cnf file and added the option:

```
bind-address=191.168.1.160
```

I still get host related errors though.


----------



## praxis (Mar 19, 2012)

I accidentally copied the line numbers 14, 15 from /etc/hosts and forgot to edit them out.  So the file really looks like:

```
::1,,...,...localhost localhost.my.domain
 127.0.0.1,..,...localhost localhost.my.domain
 192.168.1.160,..,...localhost localhost.my.domain apache
```


----------



## praxis (Mar 20, 2012)

Once I stopped messing around with host name related changes *I* figured out the problem.  I believe there is a jail conflict with stdout, stderr, and ttys.  The mysql tools work fine with redirection (<) when *I* omit -p (password) option.  You can circumvent this problem by either ssh'ing into the jail or using tmux.  

More information can be found here:

```
http://lists.freebsd.org/pipermail/freebsd-jail/2011-August/001599.html
```
and here:

```
http://forums.freebsd.org/showthread.php?t=22889
```

Now *I* want four hours of my time back.


----------



## SirDice (Mar 20, 2012)

Don't assign any other IP address than 127.0.0.1 or ::1 to localhost. Those commas and periods should be there either.


```
::1                     localhost localhost.my.domain
127.0.0.1               localhost localhost.my.domain
```
If you need your hostname to resolve add it like so:

```
192.168.1.160            myhost.mydomain
```
Replace myhost.mydomain for the FQDN of your jail's hostname.


----------



## praxis (Mar 20, 2012)

My /etc/hosts in the jail apache looks like this now:

```
::1             localhost localhost.my.domain
127.0.0.1       localhost localhost.my.domain
192.168.1.160   apache apache.my.domain apache
```

I have also bound mysql to the ip 192.168.1.160

The periods, commas and line numbers were all artifacts from vim that I forgot to remove when pasting into the reply box.  I couldn't edit the posts (seems I need a minimum of ten posts for that).   Every thing seems to be working now.    Thanks for your help, it was appreciated.


----------

