A MySQL development environment with Docker and phpMyAdmin for learning MySQL
Follow the steps below to set up a GitHub Codespace. Codespaces offer a cloud-based development environment that makes it easy to get started without any local setup.
- Clone this repository to your own GitHub account by clicking the "Fork" button in the top right corner of the repository page.
- Navigate to your repository on GitHub.
- Click on the Settings tab at the top of the repository page.
- In the left sidebar, scroll down and find the "Secrets and variables" section.
- Click on Codespaces under this section.
- Click the New repository secret button.
- Provide a unique name for the secret, using UPPERCASE letters with underscores (Use MYSQL_PASSWORD as the variable name, as it is defined with the same name in docker-compose.yml).
- Enter the secret value in the text box (e.g., your database password). This will be your password for logging in to the database within the Codespace environment.
- Click the "Add secret" button to save the secret.
- Go back to your repository's main page.
- Click the "Code" button (usually located near the top right).
- Select "Create codespace on main".
- Wait for a few moments while your Codespace environment is being set up.
- Open the Ports view in your Codespace.
- Click on "Add Port".
- Enter 6033 as the port number to expose.
- Once port 6033 is successfully added, it will appear in the Ports view.
- Open the Ports view in your codespace.
- Click Add Port and enter 88 as the port number.
- Once the port is added, a forwarded address for port 88 will appear. Click on the forwarded address to open phpMyAdmin.
- Use your MySQL credentials to log in and start working with your databases.
Note: It is important to verify that both ports 88 and 6033 are open and forwarded correctly to avoid any connectivity issues while working with your databases.
Note: If you delete your current Codespace and create a new one, all databases and tables you’ve created will be lost. To preserve them, make sure to back up your data using the database import/export functions.
After the codespace starts, you can log in to the MySQL database server using the following command:
mysql -u <username> -p
Replace with your MySQL username. Enter your password when prompted. Once logged in, you can execute SQL queries, such as creating databases, tables, and more.
In addition to the Codespace environment in GitHub, you will also set up a similar development environment locally on your personal device. Please follow the guidelines below:
- Clone the repository to your personal device:
git clone https://github.com/your-username/your-repository.git
- In the root directory of your cloned repository, create a new file named .env
- Open the .env file and add the following line and save the file
MYSQL_PASSWORD=yourpassword
Note Replace yourpassword with your own password. This will be your login password for the database service in the local environment.
- Make sure you have the Remote - Explorer extension installed in your local Visual Studio Code.
- When prompted, click Reopen in Container.
- Wait a couple of minutes for your local development container to set up.
Your local environment will now be ready to use, with all required dependencies and tools installed within the container.
To connect to the MySQL database server in your local environment, you will use MySQL Workbench. Follow the steps below to set up the connection.
- Open MySQL Workbench on your computer.
- Click the "+" (Add Connection) button to create a new connection.
- Provide a Connection Name: Enter a name that you will recognize later (e.g., "Local MySQL Connection").
- Hostname: Set the hostname to
127.0.0.1
. - Port: Enter
6033
as the port number. - Username: Set the username to
root
.
- Click on "Test Connection" to verify the connection settings.
- When prompted, enter the password: Use the password you specified in your
.env
file (MYSQL_PASSWORD
). - If the connection is successful, you will see a confirmation message.
- Click "OK" to save the connection.
- Optionally, check "Store in Vault" to save your password for future use, so you don’t need to re-enter it each time.
- The new connection will now appear in the Welcome section of MySQL Workbench.
- To connect in the future, simply click on the connection name and it will connect you to the database server automatically.
Tip: Storing the password in the vault will make connecting to your database faster and more convenient.