MySQL and phpMyAdmin Installation
IMPORTANT SECURITY NOTICE: The methods described below use default passwords (root
for MySQL and password
for the MySQL root user). It is CRITICAL to change these passwords immediately after installation for security reasons. Instructions for changing the passwords are provided below.
1. Prerequisites
- Ubuntu: If installing MySQL directly on Ubuntu, refer to this tutorial (consider updating to a more recent version): How to Install MySQL on Ubuntu 22.04
- Docker: Ensure Docker and Docker Compose are installed on your system if you plan to use the Docker installation method.
2. Direct MySQL Installation on Ubuntu (Optional)
This section describes installing MySQL directly on your Ubuntu system. If you prefer to use Docker, skip to section 3. The original reference tutorial is here: installation
2.1 Start MySQL Console
/usr/bin/mysql -u root -p
2.2 Change Maximum Connections (Optional)
SHOW VARIABLES LIKE "max_connections"; -- Check current max connections
SET GLOBAL max_connections = 1000; -- Increase the maximum connections (requires SUPER privilege)
2.3 Default Credentials (CHANGE IMMEDIATELY!)
- Username:
root
- Password:
password
IMPORTANT: To change the root password after installation (Ubuntu):
-
Log in to the MySQL console as root:
mysql -u root -p
-
Run the following SQL command:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOUR_NEW_PASSWORD';
FLUSH PRIVILEGES;Replace
YOUR_NEW_PASSWORD
with a strong, secure password. -
Exit the MySQL console:
exit
3. Docker Installation (Recommended)
This section describes installing MySQL and phpMyAdmin using Docker.
3.1 Install MySQL Container
3.1.1 Pull the MySQL Image
docker pull mysql:8.0.30
3.1.2 Create a Docker Network
Docker networks allow containers to communicate with each other easily. This is preferred over the --link
option, which is now considered legacy.
docker network create mynetwork
3.1.3 Run the MySQL Container
Option 1: Basic Run Command (Without Persistent Volume)
This option will NOT persist data if the container is removed. For testing purposes only.
docker run --name mysql_docker --network mynetwork -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:8.0.30
Option 2: Using a Persistent Volume (Recommended)
Persistent volumes ensure that your data is not lost when the container is stopped or removed.
docker volume create mysql_data
docker run --name mysql_docker --network mynetwork -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -v mysql_data:/var/lib/mysql -d mysql:8.0.30
3.1.4 Access the MySQL Terminal
docker exec -it mysql_docker bash
mysql --user=root --password=password
IMPORTANT: To change the root password after installation (Docker):
Follow the same procedure as described in section 2.3 from inside the container. Access the container shell as described above.
3.2 Install phpMyAdmin Container
3.2.1 Pull the phpMyAdmin Image
docker pull phpmyadmin
3.2.2 Run the phpMyAdmin Container
docker run --name phpmyadmin_docker --network mynetwork -p 8081:80 -e PMA_HOST=mysql_docker -d phpmyadmin/phpmyadmin:latest
3.3 Access phpMyAdmin
Open your web browser and navigate to:
3.3.1 Default phpMyAdmin Credentials (CHANGE IMMEDIATELY!)
- Username:
root
- Password:
password
IMPORTANT: Changing the phpMyAdmin password:
While phpMyAdmin itself doesn't have a separate password, you must still change the MySQL root password, as phpMyAdmin uses those credentials to connect to the database. Follow the instructions in section 2.3 or 3.1.4 (depending on your chosen MySQL installation method) to change the MySQL root password. The phpMyAdmin access route is:
http://localhost:8081/index.php?route=/&route=%2F
4. Creating a Database
After installing MySQL, you need to create a database to store your data.
-
Log in to the MySQL console (either on Ubuntu directly or inside the Docker container).
-
Execute the following SQL command:
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
(Replace
mydatabase
with your desired database name.)
5. Using Docker Compose (Optional)
For a more streamlined and repeatable setup, you can use Docker Compose. Create a file named docker-compose.yml
with the following content:
version: "3.9"
services:
db:
image: mysql:8.0.30
container_name: mysql_docker
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
networks:
- mynetwork
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: phpmyadmin_docker
restart: always
ports:
- "8081:80"
environment:
PMA_HOST: db
networks:
- mynetwork
depends_on:
- db
networks:
mynetwork:
volumes:
mysql_data: