# Difficulty in running MySQL (mysqld)



## aurora (Apr 12, 2010)

Hello

I have successfully installed MySQL from ports but I have difficulty in running it as a daemon.

I've put mysql_enable="YES" in /etc/rc.conf but it's no use.

When I type (as root)

`# # mysql -u mysql -p` and enter the password it returns


```
ERROR 2002 ... Can't connect to local MySQL server through socket '/tmp/mysql.sock'
```

When I type (as mysql user)

`% /usr/local/libexec/mysqld` it returns


```
100412 ... [Warning] Can't create test file /var/db/mysql/IBM.lower-test
...   Can't change dir to 'var/db/mysql' (Errcode: 13)
100412 ... [ERROR] Aborting
```

I have tried:

`# mysql_install_db` and it ran without problems but still no use.

What can I do?

Thanks.


----------



## knarf (Apr 12, 2010)

aurora72 said:
			
		

> I've put mysql_enable="YES" in /etc/rc.conf but it's no use.



Did you run /usr/local/etc/rc.d/mysql-server restart afterwards?


----------



## DutchDaemon (Apr 12, 2010)

Have you even _started_ mysql? Try `# /usr/local/etc/rc.d/mysql-server start`.


----------



## aurora (Apr 12, 2010)

Thank you for the response.

`# /usr/local/etc/rc.d/mysql-server start` works, ie command line prompt returns back without error message

`# /usr/local/etc/rc.d/mysql-server restart` also works but it asks "mysql not running? (check /var/db/mysql/IBM.EV.pid) then Starting mysql.

But in both cases, mysqld is still not there (`# ps -aucx | grep mysqld` returns nothing.


----------



## knarf (Apr 12, 2010)

Check /var/db/mysql/IBM.EV.err.

restart just tries to make sure there is no server running and stops it if needed. It did not ask, it told you there is no mysqld running, which is expected. This is why I use restart even if I just want to start.


----------



## aurora (Apr 12, 2010)

Thank you.

/var/db/mysql/IBM.EV.err gives


```
InnoDB: OS error number 13 in a file operation. The error means "mysqld does not have the access rights to the directory"
File name ./ibdata1
File operation call: 'create'
```


----------



## FBSDin20Steps (Apr 12, 2010)

After installing MySQL for the first time, you might want to:


```
# mysql_install_db --user=mysql
```

and...


```
# mysqld_safe &
```

To finish the install.

After these two commands you can setup your desired root password with:


```
# /usr/local/bin/mysqladmin -u root password 'your_passwd'
```
Hope this helps.


----------



## phoenix (Apr 12, 2010)

As mentioned in the error output, what are the permissions on /var/db/mysql?  The user that mysql runs as needs to own this directory (or, at the very least, have read/write permission to it), in order to create the database files in here.


----------



## aurora (Apr 13, 2010)

First I have changed the mod:

`# chmod -R 777 /var/db/mysql`

and only then worked mysql with

`# /usr/local/etc/rc.d/mysql-server restart`

Then I 've set the root password with:

`# /usr/local/bin/mysqladmin -u root password 'my_passwd'`

And it's working finally 

Thanks.

There's one final thing I'd like to ask though... (I think it's unnecessary to open a separate topic for it) 

So far I've been granting the Unix file permissions in a rough way, i.e. 

`# chmod -R 777 foldername.`

But I want to grant a certain user (let's say the "mysql" user) rwx permissions for a specific folder (let's say /var/db/mysql folder). How do you do it?


----------



## SirDice (Apr 13, 2010)

aurora72 said:
			
		

> First I have changed the mod:
> 
> `# chmod -R 777 /var/db/mysql`


Don't EVER do that again. NEVER make something world writable!



> But I want to grant a certain user (let's say the "mysql" user) rwx permissions for a specific folder (let's say /var/db/mysql folder). How do you do it?


See chown(1).


----------



## DutchDaemon (Apr 13, 2010)

```
drwx------  7 mysql  mysql  512 Apr 12 23:01 /var/db/mysql
```

All directories under it have the same permissions (700 (rwx,---,---), mysql:mysql), and the files in them all appear to be 660 (rw-,rw-,---), mysql:mysql.


----------



## aurora (Apr 13, 2010)

SirDice said:
			
		

> Don't EVER do that again. NEVER make something world writable!
> 
> 
> See chown(1).




I removed others access to that directory by:

`# chmod -R o-wrx /var/db/mysql`

And granted read&write permissions to mysql group by

`# chown -R :mysql /var/db/mysql`

Now the latest situation is :

`# ls -la /var/db/mysql`

drwxrwx--- 4 mysql mysql 512 Apr 13 20:11 mysql

I guess it's secure enough.


----------



## DutchDaemon (Apr 13, 2010)

See previous post. You could still take it down a notch.


----------



## aurora (Apr 13, 2010)

When I 

`# chmod -R 700 /var/db/mysql`

unfortunately 

`# /usr/local/etc/rc.d/mysql-server start`

is unable to start mysql.

What may I be missing?


----------



## aurora (Apr 13, 2010)

I've found what was missing  It is:

`# cd /var/db && chown -R mysql mysql/`

That is (as you might very clearly notice) the user mysql must own that directory.

I had confused the mysql group with the mysql user but now it's working even under the chmod 

700 mysql directory. And by the way I have learned the intricacies of Unix file permissions.

Thanks!


----------

