MySQL Docker Database Initialization
Overview
Since the development environment uses Mac, other platforms may encounter MySQL initialization issues during initial deployment and need to re-import database data. This document provides reference steps for database initialization.
Note: Mac development environments do not require database initialization.
Instructions
The following are command-line operation steps. If using visual tools such as Navicat, you can directly import the database file.
1. Start the Database Container
bash
cd upgradelink/development/mysql-8.4.3
rm -rf data
docker compose up -d2. Copy SQL File to Container
bash
cd ..
docker cp upgrade-20251125.sql upgradelink-mysql8.4.3:/tmp/init.sqlNote: Placing the file in the container's /tmp directory avoids permission issues.
3. Execute SQL File Import
bash
docker exec upgradelink-mysql8.4.3 sh -c 'mysql -u root -p"$MYSQL_ROOT_PASSWORD" upgrade < /tmp/init.sql'Note:
- Password is automatically retrieved from container environment variables (no manual input required)
- Specifies import to the
upgradedatabase (consistent with docker-compose configuration)
4. Verify Import Results
bash
docker exec -it upgradelink-mysql8.4.3 mysql -u user -puser_password upgradeAfter entering the MySQL command line, execute the following verification commands:
sql
SHOW TABLES;
SELECT COUNT(*) FROM main_table_name;
EXIT;