Database Setup Guide¶
Ethopy uses MySQL as its database backend, with DataJoint as the data management framework. This guide explains how to set up and manage the database for Ethopy.
Docker Setup (Recommended)¶
The recommended way to run the database is using Docker with the official DataJoint MySQL image.
Prerequisites¶
- Docker installed and running
- Docker Compose (usually included with Docker Desktop)
Using the Built-in Setup Command¶
The easiest way to set up the database is using the provided command:
1 |
|
This command will:
1. Check if Docker is running
2. Create a MySQL container named ethopy_sql_db
3. Set up the necessary volumes and configurations
4. Prompt for a root password
5. Start the container
The Docker container uses:
- Image: datajoint/mysql:5.7
(https://github.com/datajoint/mysql-docker)
- Port: 3306 (standard MySQL port)
- Volume: ./data_ethopy_sql_db:/var/lib/mysql
for persistent data storage
Manual Docker Setup¶
If you prefer to set up the container manually:
-
Create a
docker-compose.yaml
file:1 2 3 4 5 6 7 8 9 10
version: '2.4' services: ethopy_sql_db: image: datajoint/mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=your_password ports: - '3306:3306' volumes: - ./data_ethopy_sql_db:/var/lib/mysql
-
Start the container:
1
docker compose up -d
Remote Access¶
To access the database from another computer:
-
Update the Docker port mapping to allow external access:
1 2
ports: - '0.0.0.0:3306:3306'
-
In the computer that will run ethopy configure the section dj_local_conf in the
local_conf.json
, example:1 2 3 4 5 6 7 8
{ "dj_local_conf": { "database.host": "database_ip", "database.user": "root", "database.password": "your_password", "database.port": 3306 } }
-
Ensure the Docker host's firewall allows connections on port 3306
Verify port 3306 is available:
1 |
|
Standalone MySQL Setup¶
If you prefer not to use Docker, you can install MySQL directly:
Ubuntu/Debian¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
macOS (using Homebrew)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Windows¶
- Download and install MySQL Community Server
- Follow the installation wizard
- Use MySQL Workbench or command line to create user and grant privileges
Database Schema Setup¶
After setting up the MySQL server (either via Docker or standalone), initialize the schemas:
1 2 3 4 5 |
|
This will create the following schemas:
- lab_experiments
- lab_behavior
- lab_stimuli
Troubleshooting¶
Common Issues¶
- Connection Refused
- Check if MySQL service is running
- Verify port 3306 is not blocked by firewall
-
Ensure correct host/IP in configuration
-
Authentication Failed
- Verify username and password in
local_conf.json
-
Check user privileges in MySQL
-
Docker Container Issues
- Check Docker logs:
docker logs ethopy_sql_db
- Verify Docker daemon is running
- Check available disk space for volume
Useful Commands¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|