# Moving MySQL data dir



## ph0enix (May 2, 2009)

I'm trying to move the MySQL data dir from /var/db/mysql to /usr/mysql so I stopped MySQL, copied the contents of /var/db/mysql to /usr/mysql and updated my.cnf with:


```
mysql-data-dir=/usr/mysql/
```

...but MySQL isn't starting now.  Do I need to set the permissions on /usr/mysql in a specific way?

I'm running MySQL v.5.0.77.

Thanks! 

J.


----------



## DutchDaemon (May 2, 2009)

What are the permissions of the /usr/mysql directory? By the way, if you look at the command line of a running mysql installation (*ps axww*), you will see that a lot of stuff points to /var/db/mysql, not just the data dir. The better option would be to symlink /var/db/mysql to /usr/mysql and leave internals and flags alone.


```
40328  p0- I      0:00.01 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --
pid-file=/var/db/mysql/[redacted].pid
40379  p0- I      4:36.08 /usr/local/libexec/mysqld --defaults-extra-file=/var/db/mysql/my.cnf --basedir=/usr/local --datadir=/var/db/mysql --
user=mysql --log-error=/var/db/mysql/[redacted].err --pid-file=/var/db/mysql/[redacted].pid
```


----------



## ph0enix (May 2, 2009)

DutchDaemon said:
			
		

> What are the permissions of the /usr/mysql directory? By the way, if you look at the command line of a running mysql installation (*ps axww*), you will see that a lot of stuff points to /var/db/mysql, not just the data dir. The better option would be to symlink /var/db/mysql to /usr/mysql and leave internals and flags alone.
> 
> 
> ```
> ...



DutchDaemon to the rescue as usual 
symlinking /var/db/mysql to /usr/mysql did the trick!

Thank you! 

J.


----------



## dave (Aug 25, 2009)

To move the just db dir, you can specify in rc.conf:


```
mysql_dbdir="/usr/local/mysql/data"
```

Be sure to give mysql read-write access.


----------



## phospher (Jan 12, 2011)

Hmm, I can't seem to get this symlink correct though I've done it before...

I've ran into this very same issue and I'm trying to link /var/db/mysql to /usr/mysql

When I enter the command: [cmd=]ln -s /usr/mysql /var/db/mysql[/cmd]

I get the error: 
	
	



```
ln: /var/db/mysql/mysql: file exists
```

I should also add that if I do:[cmd=]ln -s /var/db/mysql /usr/mysql[/cmd]

Then /usr/mysql points to /var/db/mysql. 

```
mysql -> /var/db/mysql
```

Thoughts? Thanks


----------



## phospher (Jan 12, 2011)

Ah, I got it. Guess I had to mv the mysql directory over first.


----------



## ph0enix (Jan 22, 2011)

phospher said:
			
		

> I should also add that if I do:[cmd=]ln -s /var/db/mysql /usr/mysql[/cmd]
> 
> Then /usr/mysql points to /var/db/mysql.
> 
> ...



That's the way to do it.  You want /usr/mysql to point to /var/db/mysql assuming that's where you planning to store the data.


----------



## ph0enix (Jan 22, 2011)

phospher said:
			
		

> Ah, I got it. Guess I had to mv the mysql directory over first.



Not sure what you mean by this?  What exactly did you do?


----------



## phospher (Feb 9, 2011)

ph0enix said:
			
		

> Not sure what you mean by this?  What exactly did you do?





I actually wanted the mysql database to be located at /usr/mysql. I copied the database from /var/db/mysql to /usr/mysql then ran: [cmd=]ln -s /usr/mysql /var/db/mysql[/cmd]

And it worked. I *think* it wasn't working because /usr/mysql did not exist?? Not sure..


----------

