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 01:48]
admin [Install (the latest) MySQL Workbench]
vms:webdev:mysql [2014/11/03 18:09] (current)
admin [Restart MySQL]
Line 1: Line 1:
 ====== MySQL Server: Installation & Management ====== ====== MySQL Server: Installation & Management ======
-The last fundamental piece of our web development environment is, of course, a database management system of choice: MySQL.+The next fundamental piece of our web development environment is, of course, a database management system of choice: MySQL.
  
 ===== Install MySQL Server ===== ===== Install MySQL Server =====
Line 37: Line 37:
  
 ===== Add the Apache & PHP Modules ===== ===== Add the Apache & PHP Modules =====
-NEEDS TO BE ADAPTED 
 <​code>​ <​code>​
 > sudo apt-get install libapache2-mod-auth-mysql php5-mysql > sudo apt-get install libapache2-mod-auth-mysql php5-mysql
-> sudo nano /​etc/​php5/​apache2/​php.ini 
 </​code>​ </​code>​
- 
-Uncomment this line:\\ 
-;​extension=mysql.so 
- 
-Like this:\\ 
-extension=mysql.so 
  
 Now just restart Apache and you are all set!  Now just restart Apache and you are all set! 
Line 59: Line 51:
 Make sure to change yourpassword to a password of your choice. Make sure to change yourpassword to a password of your choice.
  
 +-----
 +===== Have your MySQL Databases Stored on your Host Filesystem =====
 +-----
 +<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 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.
 +
 +Let's create this directory **on the host's side** (feel free to adapt this folder location to wherever you see fit):
 +<​code>​
 +> mkdir /​home/<​username>/​Documents/​webdev/​mysql
 +</​code>​
 +
 +Then, configure it as a VirtualBox shared folder:
 +<​code>​
 +> VBoxManage sharedfolder add "​lamp-xd"​ --name "​mysql-share"​ --hostpath "/​home/<​username>/​Documents/​webdev/​mysql"​
 +</​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.