MySQL databases are the backbone of dynamic websites and web applications. Whether you are running WordPress, a custom PHP application, or an e-commerce platform, your site relies on a MySQL database to store and retrieve content, user accounts, product listings, orders, and more. This guide covers everything you need to know about creating and managing MySQL databases on your SakuraHost hosting account.
What Is a MySQL Database?
MySQL is a relational database management system (RDBMS) that organises data into structured tables with rows and columns. It is the most widely used database system for web hosting and powers applications from small blogs to large-scale enterprise platforms. MySQL uses Structured Query Language (SQL) for creating, reading, updating, and deleting data. For comprehensive reference, visit the official MySQL documentation.
Creating a New Database
Method 1: MySQL Database Wizard (Recommended for Beginners)
The Database Wizard walks you through the entire process step by step:
username_mydatabase). Click Next Step.
Method 2: MySQL Databases Interface (Advanced)
For more control, use the full MySQL Databases interface:
Connecting Your Application to the Database
After creating the database and user, you need to configure your application with the connection details. Here is a typical PHP connection example:
public_html or use environment variables. See the PHP MySQLi documentation for secure connection practices.
WordPress wp-config.php Example
If you are installing WordPress manually, edit wp-config.php with your database details:
Managing Databases with phpMyAdmin
phpMyAdmin is a powerful web-based tool for managing MySQL databases. Access it from cPanel under Databases > phpMyAdmin.
Common phpMyAdmin Tasks
- Browse tables: Click on a database in the left sidebar, then click a table name to view its contents.
- Run SQL queries: Click the SQL tab to execute custom queries directly against your database.
- Export/backup: Select the database, click Export, choose SQL format, and click Go to download a backup file.
- Import data: Click Import and upload a
.sqlfile to restore data or migrate from another server. - Optimise tables: Select all tables, choose Optimize table from the dropdown to reclaim wasted space and improve query performance.
Database Backup Best Practices
Regular database backups are essential for disaster recovery. We recommend the following approach:
- Automated backups: SakuraHost performs regular server-level backups. However, you should also maintain your own backups for critical data.
- Manual exports: Use phpMyAdmin's Export function weekly or before making significant changes to your website.
- Cron-based backups: Set up a cron job to automatically export your database on a schedule. See our knowledge base article on setting up cron jobs in cPanel for instructions.
- Off-site storage: Download backup files to your local computer or cloud storage. Do not rely solely on server-stored backups.
Database Size and Performance
Large databases can slow down your website. To keep your database running efficiently:
- Regularly clean up spam comments, post revisions, and transient data (especially in WordPress).
- Use database table indexes for frequently queried columns.
- Avoid storing large binary files (images, videos) in the database. Store them as files and reference them with URLs.
- Monitor database size in cPanel under Databases > MySQL Databases.
Troubleshooting Database Errors
"Error Establishing a Database Connection"
This common error usually indicates incorrect credentials in your application's configuration file, or that the database user is not properly assigned to the database. Verify your database name, username, and password in cPanel under MySQL Databases. Also confirm the host is set to localhost.
"Access Denied" Errors
Ensure the database user has the correct privileges assigned. Go to MySQL Databases, find the user under the database, and verify that ALL PRIVILEGES or the required specific privileges are granted.
For database-related assistance, submit a ticket at billing.sakurahost.co.tz with your domain name and the specific error message for faster troubleshooting. Learn more about MySQL optimisation from the MySQL Optimization Guide.