Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vms:webdev:mysql [2014/11/03 15:24]
admin [Have your MySQL Databases Stored on your Host Filesystem]
vms:webdev:mysql [2014/11/03 18:09] (current)
admin [Restart MySQL]
Line 69: Line 69:
 </​code>​ </​code>​
  
-Finally, let's change our VM's /etc/fstab file so has to have this shared folder mounted as our mysql storage space.+==== Prepare MySQL Storage Location ====
  
-We'll first need to identify ​the user and group id under which mysql is running, inside the VM, type:+By default all MySQL related databases files are stored under **/​var/​lib/​mysql**. What we'​ll ​do is first stop the mysql servicethen create a copy of the existing data, mount our "​host"​ shared folder with the correct access rights, replace the copied data inside ​the newly mounted directory and restart the mysql service. 
 + 
 +Inside ​the VM:
 <​code>​ <​code>​
 +> service mysql stop
 +> sudo cp -a /​var/​lib/​mysql /​var/​lib/​mysql.bak
 +
 > id mysql > id mysql
 uid=104(mysql) gid=108(mysql) groups=108(mysql) uid=104(mysql) gid=108(mysql) groups=108(mysql)
Line 78: Line 83:
 > sudo nano /etc/fstab > sudo nano /etc/fstab
 ADD: ADD:
-# automount mysqlshare as mysql root +# automount mysqlshare as mysql user 
-mysqlshare /​var/​lib/​mysql/​ vboxsf defaults,​uid=104,​gid=108 0 0+mysql-share /​var/​lib/​mysql/​ vboxsf defaults,​uid=104,​gid=108 0 0 
 + 
 +> sudo mount /​var/​lib/​mysql 
 +> cp -a /​var/​lib/​mysql.bak/​* /​var/​lib/​mysql/​
 </​code>​ </​code>​
 +
 +==== Restart MySQL ====
 +
 +All should now be in place to have MySQL use our shared folder as physical database storage location.
 +<​code>​
 +> sudo service mysql start
 +</​code>​
 +
 +=== Delete backup files ===
 +
 +Now, if all is running well, we can get rid of the backup files we initially created. In case of necessity, those files are, in fact, still present on the virtual machine'​s hard disk, unmounting the shared folder would reveal them.
 +
 +<​code>​
 +> sudo rm -r /​var/​lib/​mysql.bak
 +</​code>  ​
 +
 +-----
 +===== Install MySQL Workbench =====
 +-----
 +
 +Even though your database files will, from now on, be stored on your host filesystem, you might find it easier to use an integrated tool to manage the different aspects of your MySQL configuration (i.e. mainly users and tables management). This could be done using [[http://​www.phpmyadmin.net|PhpMyAdmin]],​ that could be deployed inside a dedicated virtual host.
 +
 +Although, my personal advise is to use the more versatile [[http://​dev.mysql.com/​downloads/​tools/​workbench/​|MySQL Workbench]] application. The primary reason being that this one will allow you to manage not only your local development databases, but also your remote production servers, all from the same interface. Using ssh tunneling, you won't even have to allow external MySQL connections on your production machines.