MySQL Database Management (Internal)
Overview
This guide covers creating and managing MySQL databases for clients using DirectAdmin.
For Team: Creating Databases
Creating a Database
Step 1: Access DirectAdmin
- Login to DirectAdmin reseller panel
- Navigate to client's account
- Or have client do it themselves
Step 2: MySQL Management
- In Account Manager section, click "MySQL Management"
- Or type "MySQL Management" in navigation filter
Step 3: Create New Database
- Click "Create new database"
- Enter database name (lowercase, no spaces)
- Set password (or auto-generate)
- Click "Create"
Database name format:
- Format:
username_dbname - Example:
clientname_wordpress - DirectAdmin automatically prefixes with username
Creating Database Users
Step 4: Select Database
- View list of databases
- Select the database you want to add user to
Step 5: Create New User
- Under "Users" section, click "Create New User"
Step 6: User Details
- Enter username (will be prefixed like:
username_dbuser) - Enter password or use "Generate new password" button
- Click "Create"
Step 7: Copy Credentials
- Save database details:
- Database name
- Username
- Password
- Host (usually
localhost)
- Store securely or provide to client
Database Connection Details
Standard configuration for clients:
Database Host: localhost
Database Name: username_dbname
Database User: username_dbuser
Database Password: [password set]
Port: 3306 (default)
If client needs remote MySQL access, you'll need to add their IP address in MySQL Management → Access Hosts
Managing Databases
Accessing phpMyAdmin
For database management:
- DirectAdmin → MySQL Management
- Click database name
- Click "phpMyAdmin" button
- Manage tables, run queries, import/export
Modifying User Permissions
Grant specific permissions:
- Select database
- Click on username
- Choose permissions (SELECT, INSERT, UPDATE, DELETE, etc.)
- Save
Full access (typical):
- SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
Read-only access:
- SELECT only
Changing Database Password
- MySQL Management
- Select database
- Click on username
- Enter new password
- Update client's configuration files with new password
Deleting Database/User
Deleting a database is permanent and cannot be undone!
Before deleting:
- Confirm with client
- Take backup first
- Verify they don't need the data
To delete:
- MySQL Management
- Select database or user
- Click delete icon
- Confirm deletion
Remote MySQL Access
Enabling Remote Access
When client needs external access (e.g., from their local machine):
-
Get client's IP address
- Ask them to visit: whatismyip.com
- Note their public IP
-
Add Access Host
- MySQL Management → Access Hosts
- Enter client's IP address
- Or use
%for any IP (not recommended - security risk) - Click "Add"
-
Provide connection details
Host: da.alfieweb.com (or server IP)
Port: 3306
Database: username_dbname
User: username_dbuser
Password: [password]
Security note:
- Remote access increases security risk
- Only enable when necessary
- Use strong passwords
- Consider removing after use
- Monitor for unauthorized access
Testing Remote Connection
Using MySQL command line:
mysql -h da.alfieweb.com -P 3306 -u username_dbuser -p username_dbname
Using MySQL Workbench:
- Create new connection
- Enter hostname, port, username, database
- Test connection
Common Database Tasks
WordPress Database Setup
For WordPress installations:
- Create database:
username_wp - Create user:
username_wpuser - Provide client with details
In wp-config.php:
define( 'DB_NAME', 'username_wp' );
define( 'DB_USER', 'username_wpuser' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );
Importing Database
Via phpMyAdmin:
- Access phpMyAdmin
- Select database
- Click "Import" tab
- Choose SQL file
- Click "Go"
Via command line (faster for large databases):
mysql -u username_dbuser -p username_dbname < backup.sql
File size limits:
- phpMyAdmin: Usually 50-128MB limit
- For larger: Use command line or increase PHP limits
- Split large files if needed
Exporting/Backing Up Database
Via phpMyAdmin:
- Select database
- Click "Export" tab
- Choose "Quick" or "Custom"
- Select format (usually SQL)
- Click "Go"
Via command line:
mysqldump -u username_dbuser -p username_dbname > backup.sql
Automated backups:
- DirectAdmin daily backups include databases
- Manual backups before major changes
- Test restoration periodically
Optimizing Database
When client reports slow database:
Via phpMyAdmin:
- Select database
- Check all tables
- Click "Optimize table"
Via command line:
mysqlcheck -o username_dbname -u username_dbuser -p
Repair corrupted tables:
mysqlcheck -r username_dbname -u username_dbuser -p
Troubleshooting
"Error establishing database connection"
Common causes:
- Wrong credentials
- Database doesn't exist
- User not added to database
- MySQL service down
Solution:
- Verify credentials in config file
- Check database exists in DirectAdmin
- Verify user has permissions
- Check MySQL running:
systemctl status mysqld
"Too many connections"
Cause: MySQL connection limit reached
Check:
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';
Solution:
- Close idle connections
- Optimize application connection handling
- Increase max_connections (if needed)
- Investigate connection leaks
"Access denied for user"
Causes:
- Wrong password
- Wrong username
- User not granted access to database
- Connecting from unauthorized host
Solution:
- Verify username/password correct
- Check user exists and has database permissions
- For remote: Verify IP in Access Hosts
Database Locked / Tables Crashed
Symptoms: Can't read/write to tables
Solution:
# Repair tables
mysqlcheck -r --all-databases -u root -p
# Or in phpMyAdmin: Select table → Repair table
Slow Queries
Diagnose:
- Enable slow query log
- Review query performance
- Check for missing indexes
- Optimize problematic queries
Common issues:
- Missing indexes on large tables
- Poorly written queries
- Large result sets
- Too many JOINs
Solutions:
- Add indexes
- Optimize queries
- Enable query cache
- Use caching layers (Redis, Memcached)
Best Practices
For Team
-
Naming convention:
- Use descriptive names
- Keep consistent format
- Document purpose
-
Security:
- Strong passwords always
- Limit remote access
- Regular backups
- Monitor for suspicious activity
-
Performance:
- Regular optimization
- Monitor database sizes
- Clean up old/unused databases
- Index appropriately
-
Documentation:
- Note database purpose in client records
- Document custom configurations
- Keep credentials in password manager
For Clients (Guide them)
- Use prepared statements - Prevent SQL injection
- Close connections - Don't leave hanging
- Backup regularly - Before major changes
- Optimize queries - Index properly
- Clean up data - Remove old/unused records
- Monitor size - Keep within plan limits
Database Quotas
Check database sizes:
# Login to MySQL as admin
mysql -u root -p
# Check all database sizes
SELECT
table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
If client exceeds quota:
- Notify client
- Suggest optimization/cleanup
- Offer plan upgrade
- Monitor growth trends
Advanced: Managing from Command Line
For team use:
List all databases:
mysql -u root -p -e "SHOW DATABASES;"
Create database:
mysql -u root -p -e "CREATE DATABASE username_dbname;"
Create user:
mysql -u root -p -e "CREATE USER 'username_dbuser'@'localhost' IDENTIFIED BY 'password';"
Grant permissions:
mysql -u root -p -e "GRANT ALL PRIVILEGES ON username_dbname.* TO 'username_dbuser'@'localhost';"
mysql -u root -p -e "FLUSH PRIVILEGES;"
Delete database:
mysql -u root -p -e "DROP DATABASE username_dbname;"
Quick Reference
| Task | Location in DirectAdmin |
|---|---|
| Create database | MySQL Management → Create new database |
| Create user | Select database → Create New User |
| phpMyAdmin access | Click database → phpMyAdmin button |
| Remote access | MySQL Management → Access Hosts |
| View size | MySQL Management (shows size per DB) |
| Backup database | phpMyAdmin → Export |
| Import database | phpMyAdmin → Import |
Support Scenarios
Client: "I need a database for WordPress" → Create database, user, provide credentials, guide through wp-config.php
Client: "Database connection error" → Verify credentials, check database/user exists, test connection
Client: "Need to import large database" → Use command line or increase limits, offer to do it for them
Client: "Need remote access" → Get their IP, add to Access Hosts, provide connection details, security warning
Client: "Database slow" → Check size, optimize tables, review queries, consider upgrade
Tip: Most clients can manage their own databases via DirectAdmin. Only intervene when they have issues or need assistance.