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:11]
admin [Have your MySQL Databases Stored on your Host Filesystem]
vms:webdev:mysql [2014/11/03 18:09] (current)
admin [Restart MySQL]
Line 54: Line 54:
 ===== Have your MySQL Databases Stored on your Host Filesystem ===== ===== Have your MySQL Databases Stored on your Host Filesystem =====
 ----- -----
-<color darkslateblue>​**This is for a VirtualBox system only**</​color>​ +<color darkslateblue>​**This is for a VirtualBox system only**</​color>​\\ 
-As was done for our Virtual Hosts files, we'll configure our VirtualBox VM so that all our database files will be stored inside a directory that does not reside inside our VM'​s ​filesystem ​but rather on our host's filesystem.+As was done for our Virtual Hosts files, we'll configure our VirtualBox VM so that all our database files will be stored inside a directory that does not reside inside our VM's but rather on our host's filesystem.
  
 Please refer to [[vms:​webdev:​apache#​create_the_shared_www_folders|the apache virtual host setup section]] for deeper details on this configuration,​ as it relies on the same principles. Please refer to [[vms:​webdev:​apache#​create_the_shared_www_folders|the apache virtual host setup section]] for deeper details on this configuration,​ as it relies on the same principles.
Line 67: Line 67:
 <​code>​ <​code>​
 > VBoxManage sharedfolder add "​lamp-xd"​ --name "​mysql-share"​ --hostpath "/​home/<​username>/​Documents/​webdev/​mysql"​ > VBoxManage sharedfolder add "​lamp-xd"​ --name "​mysql-share"​ --hostpath "/​home/<​username>/​Documents/​webdev/​mysql"​
-</​code> ​+</​code>​ 
 + 
 +==== Prepare MySQL Storage Location ==== 
 + 
 +By default all MySQL related databases files are stored under **/​var/​lib/​mysql**. What we'll do is first stop the mysql service, then 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>​ 
 +> service mysql stop 
 +> sudo cp -a /​var/​lib/​mysql /​var/​lib/​mysql.bak 
 + 
 +> id mysql 
 +uid=104(mysql) gid=108(mysql) groups=108(mysql) 
 + 
 +> sudo nano /​etc/​fstab 
 +ADD: 
 +# automount mysqlshare as mysql user 
 +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>​ 
 + 
 +==== 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.