Install MySQL on CasaOS with the Docker Official Image, a persistent /var/lib/mysql volume, and an explicit version tag. Do not rely on an old 2023 screenshot or a floating latest tag for a database you care about.
As of September 2026, the official Docker image publishes MySQL 8.4 LTS as well as newer 9.x/innovation lines. For long-lived self-hosted services, 8.4 is a sensible compatibility baseline unless your application explicitly supports a newer major version.
Use the Official MySQL Image
The current MySQL Docker Official Image is maintained by the Docker Community and MySQL Team.
Choose a Version Tag Deliberately
Use a pinned major/LTS tag such as:
mysql:8.4
rather than blindly following latest, which can move to a newer major release with compatibility changes.
Persistent CasaOS Settings
-
Image:
mysql:8.4 -
Container port:
3306 -
Persistent volume: host AppData path →
/var/lib/mysql - MYSQL_ROOT_PASSWORD: strong bootstrap root password
-
Optional:
MYSQL_DATABASE,MYSQL_USER,MYSQL_PASSWORD
Do Not Expose Port 3306 to the Internet
If another Docker app on the same host needs MySQL, put both services on a shared Docker network and use the service name. You often do not need to publish 3306 at all.
Create an Application User Instead of Using Root
Use MYSQL_DATABASE, MYSQL_USER, and MYSQL_PASSWORD during first initialization to create an application-specific database and account.
Keep root for administration and recovery.
Understand First-Run Environment Variables
The official image initializes the database only when the data directory is empty. Changing bootstrap environment variables later does not automatically rewrite existing accounts or databases.
Back Up with Logical Dumps
For portable backups, use mysqldump or the official image's documented dump/restore pattern rather than copying active database files while MySQL is writing.
Connect phpMyAdmin or Another App by Service Name
On a shared Docker network, a web app can connect to MySQL using a service/container hostname such as mysql. Inside another container, localhost refers to that container itself.
The Docker networking guide explains that container-network model.
Check MySQL Health Before Connecting Other Apps
After the first start, do not immediately point production applications at the database. Check the container logs and verify that MySQL has completed initialization rather than remaining in a restart loop.
docker logs mysql
docker exec -it mysql mysqladmin -uroot -p ping
A healthy server should respond after the initial database setup finishes. First boot can take longer because the image creates system tables, users, and the requested database.
Plan Character Set and Timezone Before Importing Data
Applications can have specific collation, character-set, or timezone expectations. If you are migrating an existing database, compare the old server's MySQL major version and configuration before importing.
Do not assume an application tested on MySQL 8.0 will automatically support MySQL 9.x simply because the container starts. Pin the major version required by the application vendor.
Separate Database Storage from General Shared Folders
MySQL data files should live on reliable local storage with consistent permissions and low latency. Do not place /var/lib/mysql on an unreliable SMB mount or removable drive just because it has more capacity.
If the CasaOS host has an SSD and a larger HDD pool, the SSD is often the better database location while scheduled dumps can be copied to the larger backup storage.
FAQ
Should I use mysql:latest?
Prefer a deliberate major/LTS tag for production-like self-hosting so a routine pull does not unexpectedly jump major versions.
Where should MySQL data persist?
Map a host AppData folder to /var/lib/mysql.
Do I need to publish port 3306?
Not when only other containers on the same Docker network need the database.
Can I change MYSQL_ROOT_PASSWORD later by editing the container variable?
Not reliably after initialization. Manage existing database accounts from MySQL itself.
