Creating databases and users, using phpMyAdmin, and taking backups.
Contents
- Opening MySQL Databases
- Creating a database
- Method 1: using MySQL Databases
- Method 2: using the MySQL Database Wizard (step by step)
- Creating a database user
- Password Generator
- Adding a user to a database
- Types of privilege
- Managing existing databases
- Viewing databases
- Checking the size of a database
- Deleting a database
- Renaming a database
- Managing database users
- Viewing users
- Changing a user’s password
- Deleting a user
- Removing a user’s privileges
- Working with phpMyAdmin
- Opening phpMyAdmin
- Basic operations in phpMyAdmin
- Backing up databases
- Method 1: using Backup in cPanel
- Method 2: using phpMyAdmin
- Method 3: from the command line (SSH)
- Automatic backups
- Restoring databases
- Using Backup
- Using phpMyAdmin
- Monitoring and optimisation
- Checking performance
- Optimising queries
- Adding indexes
- Clearing out unused data
- Troubleshooting common problems
- Database connection error
- Too many connections
- Table doesn’t exist
- The database is too large
- I can’t import a large database
- Database security
- Best practice
- Protecting against SQL injection
- Limits and quotas
- See also
- Useful SQL queries
- Basic operations
- External links
MySQL is a relational database management system (RDBMS) used by most popular CMSs (WordPress, Joomla, Drupal) and web applications.
Opening MySQL Databases
- Log in to cPanel
- In the DATABASES section, choose MySQL® Databases
- The database management page opens
Creating a database
Method 1: using MySQL Databases
- Go to the Create New Database section
- Enter a name for the database (your account prefix is added automatically)
- Example: if you enter
mysite, the database is namedusername_mysite
- Example: if you enter
- Click Create Database
- A message confirms that the database has been created
- Click Go Back to return
Method 2: using the MySQL Database Wizard (step by step)
- Go to MySQL® Database Wizard
- Step 1: Create a database
- Enter a database name
- Click Next Step
- Step 2: Create a user
- Enter a username
- Enter a password (or use the Password Generator)
- Click Create User
- Step 3: Assign privileges
- Choose ALL PRIVILEGES for full access
- Or choose specific privileges
- Click Next Step
- Step 4: Finish
- Make a note of the connection details
- The database is ready to use
Creating a database user
Database users are needed to connect to databases.
- In the MySQL Users section → Add New User
- Enter a Username (the prefix is added automatically)
- Enter a Password or use the generator
- The password strength must be at least “Good” (preferably “Strong”)
- Click Create User
Password Generator
To create a strong password:
- Click Password Generator
- Set the options:
- Length: at least 12 characters (16–20 recommended)
- Include special characters
- Include numbers
- Include capital letters
- Click Generate Password
- Copy the password (click Use Password)
Adding a user to a database
A user must be linked to a database before it can access it.
- In the Add User To Database section
- Choose a User from the drop-down list
- Choose a Database from the list
- Click Add
- Choose the privileges:
Types of privilege
| Privilege | Description | When to use it |
|---|---|---|
| ALL PRIVILEGES | Full access to all operations | For applications (WordPress, Joomla and so on) |
| SELECT | Reading data | For read-only users |
| INSERT | Adding new records | For data-collection forms |
| UPDATE | Changing existing records | For applications that edit data |
| DELETE | Deleting records | For administrative functions |
| CREATE | Creating new tables | For CMS installers |
| DROP | Deleting tables | For administrative functions |
| INDEX | Creating and deleting indexes | For optimising the database |
| ALTER | Changing the structure of tables | For database structure updates |
- Click Make Changes
Managing existing databases
Viewing databases
The Current Databases section shows:
- The database name
- The size of the database
- The users assigned to it
- Actions (rename, delete)
Checking the size of a database
- Look at the Size column in the list of current databases
- Or use phpMyAdmin for a more detailed analysis
- Keep an eye on usage against your account quota
Deleting a database
- Find the database in the Current Databases list
- Click Delete next to the database you want to remove
- Confirm the deletion
Renaming a database
- Click Rename next to the database
- Enter the new name
- Click Proceed
Managing database users
Viewing users
The Current Users section lists all MySQL users.
Changing a user’s password
- Find the user in the Current Users section
- Click Change Password
- Enter a new password, or use the generator
- Click Change Password
Deleting a user
- Click Delete next to the user
- Confirm the deletion
Removing a user’s privileges
- In the Current Databases section, find the database
- Next to the user’s name, click X (remove privileges)
- Confirm the action
Working with phpMyAdmin
phpMyAdmin is a web interface for managing MySQL databases.
Opening phpMyAdmin
- In the DATABASES section, click phpMyAdmin
- The interface opens in a new tab
- The list of databases is on the left
Basic operations in phpMyAdmin
Viewing tables
- Select a database in the left-hand panel
- A list of tables is shown
- Click a table to see its data
Running SQL queries
- Select a database
- Go to the SQL tab
- Enter an SQL query, for example:
SELECT * FROM wp_users WHERE user_login = 'admin';- Click Go
Exporting a database
- Select a database
- Go to the Export tab
- Choose a method:
- Quick — a quick export with the default settings
- Custom — an export you can configure
- Format: usually SQL
- Click Go
- The .sql file is downloaded to your computer
Importing a database
- Select a database
- Go to the Import tab
- Click Choose File
- Select the .sql file
- Click Go
- Wait for the import to finish
Optimising tables
- Select a database
- Tick the tables to optimise (or click Check All)
- In the With selected drop-down menu, choose Optimize table
- Click Go
Repairing tables
If a table is damaged:
- Select the table
- In the With selected menu, choose Repair table
- Click Go
Search and replace
- Select the table
- Open the Search tab
- Enter your search criteria
- Or use SQL:
UPDATE wp_options
SET option_value = REPLACE(option_value, 'old-domain.com', 'new-domain.com');Backing up databases
Method 1: using Backup in cPanel
- Go to Backup
- In the Download a MySQL Database Backup section
- Click the name of the database
- A .sql.gz file is downloaded to your computer
Method 2: using phpMyAdmin
See the section Exporting a database
Method 3: from the command line (SSH)
mysqldump -u username_dbuser -p username_dbname > backup.sqlAutomatic backups
Set this up with Cron Jobs:
- Go to Cron Jobs
- Add a job:
0 2 * * * mysqldump -u username_dbuser -p'password' username_dbname | gzip > /home/username/backups/db_$(date +\%Y\%m\%d).sql.gzRestoring databases
Using Backup
- Go to Backup
- Open the Restore a MySQL Database section
- Click Choose File
- Select the .sql or .sql.gz file
- Click Upload
Using phpMyAdmin
See the section Importing a database
Monitoring and optimisation
Checking performance
- In phpMyAdmin, select the database
- The Status tab shows:
- Table sizes
- The number of records
- Overhead (unused space)
Optimising queries
Use EXPLAIN to analyse a query:
EXPLAIN SELECT * FROM wp_posts WHERE post_status = 'publish';Adding indexes
To speed up searches:
CREATE INDEX idx_post_status ON wp_posts(post_status);Clearing out unused data
For WordPress:
-- Delete post revisions
DELETE FROM wp_posts WHERE post_type = 'revision';
-- Empty the trash
DELETE FROM wp_posts WHERE post_status = 'trash';
-- Delete spam comments
DELETE FROM wp_comments WHERE comment_approved = 'spam';
-- Optimise the tables after clearing out
OPTIMIZE TABLE wp_posts, wp_comments;Troubleshooting common problems
Database connection error
Error establishing a database connection
Causes and solutions:
- Incorrect connection details
- Check the database name, username and password in the configuration file
- Make sure the user has been added to the database
- The MySQL server isn’t running
- Contact our support team
- Too many connections
- Optimise your code
- Check for infinite loops
- Damaged tables
- Use Repair in phpMyAdmin
Too many connections
The limit on simultaneous connections has been exceeded:
Solutions:
- Use persistent connections
- Optimise your queries
- Turn on caching
- Contact us to ask for a higher limit
Table doesn’t exist
Causes:
- The table really is missing
- A mistake in the table name (case matters!)
- No database has been selected
Solution:
-- List the existing tables
SHOW TABLES;
-- Check the table structure
SHOW CREATE TABLE table_name;The database is too large
Symptoms:
- Slow performance
- Quota exceeded
- Errors when taking backups
Solutions:
- Clear out unused data
- Optimise the tables
- Archive old data
- Use external storage for files
- Upgrade your hosting plan
I can’t import a large database
Limits:
- PHP memory_limit
- PHP max_execution_time
- MySQL max_allowed_packet
- The size of the uploaded file
Solutions:
- Raise the limits in MultiPHP INI Editor
- Split the dump into parts
- Use the BigDump script
- Import over SSH:
mysql -u username_dbuser -p username_dbname < backup.sqlDatabase security
Best practice
- Strong passwords
- At least 16 characters
- Letters, numbers and special characters
- Minimum privileges
- Give only the privileges that are needed
- Don’t use the root account
- Regular backups
- At least once a day for critical data
- Keep copies off the server
- Updates
- Update your CMS and plugins regularly
- Apply security patches
- Monitoring
- Check the logs for suspicious activity
- Use intrusion detection systems
Protecting against SQL injection
In your PHP code, use:
Prepared statements (mysqli):
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();PDO:
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->execute(['username' => $username]);Never do this:
// ❌ DANGEROUS - vulnerable to SQL injection!
$query = "SELECT * FROM users WHERE username = '$username'";Limits and quotas
Typical hosting limits:
| Setting | Typical value | Description |
|---|---|---|
| Number of databases | 10–100 | Depends on the plan |
| Database size | 1–10 GB | Per database |
| Simultaneous connections | 10–50 | Parallel connections |
| max_allowed_packet | 16–64 MB | Maximum packet size |
| Table size | Unlimited | Limited by the size of the database |
Check your limits in the right-hand panel of cPanel.
See also
- A detailed guide to phpMyAdmin
- Optimising MySQL performance
- Backups
- An alternative: PostgreSQL
- Database security
Useful SQL queries
Basic operations
-- Create a table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert data
INSERT INTO users (username, email) VALUES ('john', 'john@example.com');
-- Update data
UPDATE users SET email = 'newemail@example.com' WHERE username = 'john';
-- Delete data
DELETE FROM users WHERE id = 5;
-- Select data
SELECT * FROM users WHERE created_at > '2024-01-01';
-- Count records
SELECT COUNT(*) FROM users;
-- Sort
SELECT * FROM users ORDER BY created_at DESC LIMIT 10;External links
Didn’t find the answer? Ask our support team — we’ll help.