This is an old revision of the document!
MySQL Server: Installation & Management
The next fundamental piece of our web development environment is, of course, a database management system of choice: MySQL.
Install MySQL Server
Installing MySQL server is an easy task, simply issue the following commands in a Terminal window:
> sudo apt-get install mysql-server
You will be asked to enter the password you wish to set for the mysql root user.
Once the install process has completed, verify that mysql is running using:
> sudo service mysql status
Easy! Once you have installed MySQL, we should activate it with this command:
> sudo mysql_install_db
Finish up by running the MySQL set up script:
> sudo /usr/bin/mysql_secure_installation
Let Your MySQL Server Be Accessed From the Outside
In order for other computers on your network to view the server you have created, you must first edit the “Bind Address”. Begin by opening up Terminal to edit the my.cnf file.
> sudo nano /etc/mysql/my.cnf
Change the line
bind-address = 127.0.0.1
Changing the 127.0.0.1 to your IP address.
Add the Apache & PHP Modules
> sudo apt-get install libapache2-mod-auth-mysql php5-mysql
Now just restart Apache and you are all set!
Change the root User's Password
It is fundamental to protect access to you databases, setting a root password is essential to this point. In case the installer didn't ask you for a password, or you left it blank, you'll have to set it “manually”, here is how:
Note that the same procedure can be used to change the current root user's password.
mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
Make sure to change yourpassword to a password of your choice.
Have your MySQL Databases Stored on your Host Filesystem
This is for a VirtualBox system only 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.
Please refer to 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 where you see fit):
> mkdir /home/<username>/Documents/webdev/mysql
Then, configure it as a VirtualBox shared folder: