How to create a MySQL database and use phpMyAdmin

Before you start

Most websites need four database values:

  • Database host
  • Database name
  • Database username
  • Database password

On Webway hosting the database host is localhost. Database names and usernames receive an automatic account prefix. Use the complete values shown by the control panel.

Create a database in cPanel

  1. Sign in to cPanel.
  2. Open Databases.
  3. Select MySQL Databases or MySQL Database Wizard.
  4. Enter a name for the database.
  5. Create a database user with a strong password.
  6. Add the user to the database.
  7. Grant the permissions required by the application.

Most website applications require All Privileges.

Create a database in DirectAdmin

  1. Sign in to DirectAdmin.
  2. Open Account Manager.
  3. Select Databases.
  4. Select Create Database.
  5. Enter the database and user details.
  6. Generate or enter a strong password.
  7. Create the database.

Store the password securely. The application needs the same password in its configuration.

Open phpMyAdmin

cPanel

  1. Open Databases.
  2. Select phpMyAdmin.

DirectAdmin

Open Extra Features → phpMyAdmin.

Select the correct database in the left-hand menu before importing, exporting or editing anything.

Import a database

  1. Open phpMyAdmin.
  2. Select the destination database.
  3. Open the Import tab.
  4. Choose the .sql, .sql.gz or supported archive from your computer.
  5. Keep the format set to SQL.
  6. Start the import.
  7. Wait for the success or error message.

Import into an empty database unless the application's migration instructions say otherwise. Importing over existing tables can cause conflicts or duplicate data.

Export a database

  1. Open phpMyAdmin.
  2. Select the database.
  3. Open the Export tab.
  4. Choose Quick for a normal complete export.
  5. Select SQL as the format.
  6. Start the export.
  7. Save the file somewhere secure.

Use Custom if you need specific tables, compression or advanced options.

Import a large database

phpMyAdmin has an upload-size and execution-time limit.

For a large database, try:

  1. Compressing the SQL file as .gz.
  2. Splitting the export into smaller valid SQL files.
  3. Asking Webway Support to import it for you on the server.

SSH is switched off by default on shared hosting. If SSH has been enabled for your account, you can import with:

mysql -u DATABASE_USER -p DATABASE_NAME < backup.sql

Do not place database backups in public_html. If you must upload one temporarily, remove it immediately after the import.

Connect your website

Add the complete database details to your website's configuration.

For a typical PHP application:

Database host: localhost
Database name: ACCOUNT_database
Database user: ACCOUNT_user
Database password: your secure password

Use the exact prefixed names shown by your control panel.

If the website cannot connect

Check that:

  • The database exists.
  • The user exists.
  • The user is assigned to the database.
  • The user has the required privileges.
  • The application uses the complete prefixed names.
  • The password matches.
  • The database host is localhost.

Did this answer it?