Step 1: Update .zshrc File with Additional Database Details
If you want to add credentials or another database, you can simply add a new set of environment variables to your .zshrc file.
Open your .zshrc file in VS Code (or any text editor):
code ~/.zshrcAdd the new database credentials at the bottom of the file, just like you did for the previous database. You can name the variables differently to avoid conflicts.
For example, if the new database is called new_database:
Step 2: Save and Reload .zshrc
Once you've added the new environment variables, save the file and reload the .zshrc to apply the changes:
code ~/.zshrcStep 3: Verify the New Environment Variables
Make sure that the new environment variables have been correctly set by running:
echo $DATABASE_URL
echo $STUDENT_DB_URLEach command should print the expected values.
Step 4: Use the New Database in Your Jupyter Notebook or Python Script
Now that you've added the new database credentials, you can use them in your Python script or Jupyter notebook by accessing the new environment variables.
For example, in Jupyter or Python:
Step 5: Switching Between Databases in Jupyter Notebook
You can switch between the two databases by simply changing the connection string depending on which database you want to query.
For example, to use the classicmodels database:
%sql {connection_string_classicmodels}And to switch to the new_database:
%sql {connection_string_new_database}Step 6: Optional - Add More Databases
If you need to add more databases in the future, follow the same steps:
- Add more environment variables in
.zshrcfor each new database. - Update the connection strings in your Python or Jupyter notebook.
By doing this, you can easily manage multiple databases in your environment without exposing sensitive information.