Demystifying MariaDB, MySQL, and Docker: Enabling Remote Connections

2024-07-27

MariaDB: MariaDB is a popular open-source relational database management system (RDBMS) that's functionally compatible with MySQL. It's often used in Docker containers for persistent data storage.

MySQL: While MariaDB is a distinct product, it shares a lot of syntax and functionality with MySQL. Many tools and concepts related to MySQL can also be applied to working with MariaDB.

Remote Access Steps:

  1. Connect from Remote Machine: Once the port is exposed, you can use a MySQL client program on your remote machine to connect to the MariaDB database. You'll need the following information:

    • Hostname/IP Address: The IP address or hostname of the Docker host machine.
    • Port: The port you mapped to the container's port 3306 (e.g., 3307 on the host).
    • Username: A valid MariaDB username with remote access privileges.
    • Password: The password for the remote user.

Security Considerations:

  • Exposing databases to remote connections can be a security risk. It's essential to use strong passwords, consider using a VPN for access, and only allow connections from authorized IP addresses.
  • For development environments, it might be sufficient to access the database from the local machine using the container's internal IP address.



docker run -d \
  --name my-mariadb \
  -e MYSQL_ROOT_PASSWORD=strong_password \
  -p 3307:3306 \
  mariadb:latest

This command does the following:

  • docker run -d: Runs the container in detached mode (background).
  • --name my-mariadb: Names the container for easier identification.
  • -e MYSQL_ROOT_PASSWORD=strong_password: Sets the root password for the MariaDB user. Replace "strong_password" with a secure password.
  • -p 3307:3306: Maps the container's port 3306 (MariaDB) to port 3307 on the Docker host machine. You can choose any unused port on the host.
  • mariadb:latest: Specifies the MariaDB Docker image (latest version).

Connecting from a Remote Machine (using a MySQL client):

Assuming you're on a remote machine with a MySQL client installed and the Docker host machine has IP address 192.168.1.100, you can connect with:

mysql -h 192.168.1.100 -P 3307 -u root -p
  • mysql: The MySQL client program.
  • -h 192.168.1.100: Hostname/IP address of the Docker host machine.
  • -P 3307: Port number mapped on the host machine (from step 1).
  • -u root: Username to connect to MariaDB (replace with your allowed user if not root).
  • -p: Prompts for the password (enter the password you set in step 1).



  • Advantages:

    • More secure as the database port isn't directly accessible from the outside world.
    • Easier management for multi-container applications where multiple services need to access the database.
    • Requires additional configuration to set up the custom network.
    • Might be less intuitive for simple development setups.

SSH Tunneling:

    • Leverages existing SSH infrastructure for secure communication.
    • No need to modify the MariaDB configuration or expose ports directly.
    • Requires an SSH server running on the Docker host machine.
    • Adds an extra step of setting up the tunnel before connecting to the database.

Volume Mounts:

    • Simplifies data management and backups.
    • Database data persists even after container restarts.

mysql docker mariadb



Example Code (Schema Changes Table)

Create a table in your database specifically for tracking changes. This table might have columns like version_number (integer...


Visualize Your MySQL Database: Reverse Engineering and ER Diagrams

Here's a breakdown of how it works:Some popular tools for generating MySQL database diagrams include:MySQL Workbench: This free...


Level Up Your MySQL Skills: Exploring Multiple Update Techniques

This is the most basic way. You write separate UPDATE statements for each update you want to perform. Here's an example:...


Retrieving Your MySQL Username and Password

Understanding the Problem: When working with MySQL databases, you'll often need to know your username and password to connect...


Managing Databases Across Development, Test, and Production Environments

Developers write scripts containing SQL statements to define the database schema (structure) and any data changes. These scripts are like instructions to modify the database...



mysql docker mariadb

Optimizing Your MySQL Database: When to Store Binary Data

Binary data is information stored in a format computers understand directly. It consists of 0s and 1s, unlike text data that uses letters


Enforcing Data Integrity: Throwing Errors in MySQL Triggers

MySQL: A popular open-source relational database management system (RDBMS) used for storing and managing data.Database: A collection of structured data organized into tables


Bridging the Gap: Transferring Data Between SQL Server and MySQL

SSIS is a powerful tool for Extract, Transform, and Load (ETL) operations. It allows you to create a workflow to extract data from one source


Replacing Records in SQL Server 2005: Alternative Approaches to MySQL REPLACE INTO

SQL Server 2005 doesn't have a direct equivalent to REPLACE INTO. You need to achieve similar behavior using a two-step process:


When Does MySQL Slow Down? It Depends: Optimizing for Performance

Hardware: A beefier server with more RAM, faster CPU, and better storage (like SSDs) can handle much larger databases before slowing down