-
Notifications
You must be signed in to change notification settings - Fork 0
Local MySQL
When working with the database, we will follow this general guideline:
- Test our database changes on a local MySQL database
- When the next public release is ready, we will update the live database.
There are several ways to setup and access your local machine's MySQL database.
The easiest way to setup and access your local machine's MySQL database is to use MySQL Workbench. Download from here.
- Setup a valid instance and connection (read here)
- Create a database by running the query:
CREATE DATABASE PlanToGrad;
- In Workbench, open the
schema.sqlanddata.sqlfiles in thebackend/directory of the repository. - Run
schema.sqlto initialize the tables. - Run
data.sqlto populate the tables.
When testing any changes, you only need to run schema.sql if you are making changes to the tables' design (e.g. adding new columns to a table). If you just need to add/remove from the tables, you only need to run data.sql.
IMPORTANT: Running the above files will overwrite your tables. This is why it is especially important not to run it on the live database until it's ready to be updated.
You can also access your local database through the Unix command line interface.
sudo apt-get update && sudo apt-get install mysql
Use Homebrew to install:
brew install mysql-
brew tap homebrew/servicesto install brew services -
brew services start mysqlto start MySQL with brew services If you don't have it, useruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"to install it.
- Access your local mysql with
mysql -u root. Your username will be root by default and have no password. - When you see the command line prompt, run
CREATE DATABASE PlanToGrad;
- Navigate to the
backend/directory of the repository. If you are in the top directory, runcd setup - Run
mysql -u root -D PlanToGrad < schema.sqlto initialize the tables. - Run
mysql -u root -D PlanToGrad < data.sqlto populate the tables with data.
Do the above steps whenever you want to test your changes to the .sql files.