Sep 13, 2025

How To Setup MySQL and phpMyAdmin on Linux

To install MySQL on a system, the commands depend on the operating system you’re using. Here are the installation steps for common systems:

On Ubuntu/Debian:

  1. Update your package index:
  1. Install MySQL:
  1. Start MySQL service:
  1. Secure MySQL installation (set a root password and configure settings):
  1. Check MySQL status to confirm it’s running:
  1. Install PHP and required extensions:

On CentOS/RHEL:

  1. Install MySQL 8 repository:
  1. Install MySQL:
  1. Start MySQL service:
  1. Check MySQL status:
  1. Secure MySQL installation:
  1. Install PHP and required extensions:

Install phpMyAdmin:

Step 1: Download phpMyAdmin ZIP File
  1. Go to the official phpMyAdmin download page:
  1. Download the latest stable version (ZIP):
  • Choose the .zip version and download it. Alternatively, you can use the wget command to download it directly on your server:
Step 2: Extract the ZIP File
  1. Extract the downloaded ZIP file:
  • First, navigate to the directory where you want to install phpMyAdmin. For example:
  • Then extract the ZIP file:
  1. Rename the folder (optional):
    If you’d like to rename the folder to phpmyadmin for easier access, run:
Step 3: Set Permissions
  1. Set the appropriate permissions so the web server can access phpMyAdmin:
Step 4: Access phpMyAdmin
  • Open your browser and visit http://your_server_ip/phpmyadmin.
  • Log in using your MySQL username and password.
Alternative (if phpMyAdmin is installed in another directory):

If phpMyAdmin is located somewhere else (for example, /usr/share/phpmyadmin), create a symbolic link to the web root:

MySQL User Create:

Step 1: Log in to MySQL as Root
  1. Open a terminal and log in to MySQL as the root user:

You’ll be prompted to enter the root password.

Step 2: Create the MySQL User
  1. Run the following SQL command to create a new user. Replace username and password with the desired username and password:

localhost means the user can only log in from the local machine. To allow the user to log in from any IP, you can use % instead of localhost: CREATE USER 'username'@'%' IDENTIFIED BY 'password';

Step 3: Grant Full Permissions
  1. Grant the new user full permissions on a specific database (replace database_name with the name of your database):

If you want the user to have full permissions on all databases, use the following:

The WITH GRANT OPTION allows the user to grant privileges to others.

  1. Flush privileges to apply the changes:
Step 4: Verify Permissions

To verify that the user has the correct permissions, you can log in as the new user:

Then, you can check the granted permissions using the following command:

Step 5: Exit MySQL

After completing the process, exit MySQL:

Avatar photo
Md. Azaj Ikbal

Red Hat | CentOS | Ubuntu | Shell Scripting | Server Hardening | Server Clustering | Virtualization | VMware | vSphere | vCenter | ESXi | vMotion | SAN Storage | vSAN | VMware Data Center | Windows Server Domain Controller | DNS & DNS Sec | RADIUS | Cacti | Observium | GrayLog | Veeam Backup | Huawei Networking | Cisco Networking | IP Telephony | Server Admin | Network Engineer