The Linux package management system doesn't allow us to install two MySQL instances. Instead, we implement separation in the same MySQL instance by using separate databases with different usernames and access privileges for each database.
The first step is to ensure that MySQL is installed on your server. For Ubuntu, DigitalOcean has a fairly good tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-14-04. While the Ubuntu version for that tutorial is old, the instructions are still accurate enough.
The MySQL server must support TCP connections from localhost. Edit the configuration file, /etc/mysql/my.cnf, to have the following line:
bind-address = 127.0.0.1
This limits MySQL server connections to the processes on the server. A miscreant would have to break into the server to access your database. Now that our database server is available, let's set up two databases.
In the chap10/notes/models directory, create a file named mysql-create-db.sql containing the following:
CREATE DATABASE notes; CREATE USER 'notes'@'localhost' IDENTIFIED BY 'notes'; GRANT ALL PRIVILEGES ON notes.* TO 'notes'@'localhost' WITH GRANT OPTION;
In the chap10/users directory, create a file named mysql-create-db.sql containing the following:
CREATE DATABASE userauth; CREATE USER 'userauth'@'localhost' IDENTIFIED BY 'userauth'; GRANT ALL PRIVILEGES ON userauth.* TO 'userauth'@'localhost' WITH GRANT OPTION;
We can't run those scripts on the server, because the Notes application has not yet been copied to the server. When that's accomplished, we'll run the scripts as:
$ mysql -u root -p <chap10/users/mysql-create-db.sql $ mysql -u root -p <chap10/notes/models/mysql-create-db.sql
This will create the two databases, notes and userauth, with associated usernames and passwords. Each user can access only their associated database. Later, we'll set up Notes and the user authentication service with YAML configuration files to access these databases.