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:

Step 1: Log in to cPanel and navigate to Databases > MySQL Database Wizard.
Step 2: Enter a name for your database. cPanel will prefix it with your account username (e.g., username_mydatabase). Click Next Step.
Step 3: Create a database user. Enter a username and a strong password. Use the Password Generator to create a secure password. Click Create User.
Step 4: Assign privileges to the user. For most applications, select ALL PRIVILEGES. Click Next Step to complete the setup.
Save Your Credentials: Record the database name, username, and password immediately. You will need these to configure your web application. cPanel does not display passwords after creation for security reasons.

Method 2: MySQL Databases Interface (Advanced)

For more control, use the full MySQL Databases interface:

Step 1: Go to Databases > MySQL Databases in cPanel.
Step 2: Under Create New Database, enter the database name and click Create Database.
Step 3: Scroll to MySQL Users > Add New User. Enter credentials and click Create User.
Step 4: Scroll to Add User To Database. Select the user and database from the dropdowns, click Add, then select the appropriate privileges.

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:

<?php $servername = "localhost"; $username = "username_dbuser"; $password = "your_secure_password"; $dbname = "username_mydatabase"; // Create connection using MySQLi $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>
Security Note: Never hardcode database credentials in publicly accessible files. Store them in a configuration file outside 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:

define( 'DB_NAME', 'username_mydatabase' ); define( 'DB_USER', 'username_dbuser' ); define( 'DB_PASSWORD', 'your_secure_password' ); define( 'DB_HOST', 'localhost' ); define( 'DB_CHARSET', 'utf8mb4' ); define( 'DB_COLLATE', '' );

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 .sql file 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:

  1. Automated backups: SakuraHost performs regular server-level backups. However, you should also maintain your own backups for critical data.
  2. Manual exports: Use phpMyAdmin's Export function weekly or before making significant changes to your website.
  3. 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.
  4. 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.

Was this answer helpful? 0 Users Found This Useful (0 Votes)