Create a MySQL database and user

mysql, mariadb, database, user, privileges, wizard, connection · 0 found this helpful

Most apps need a database and a user that can use it. You can make both with a wizard in about two minutes.

Create both at once (easiest)

  1. Open Account → Hosting → your site → Databases.
  2. Click New database. Create a database and a user for it opens.
  3. Under Database name, type a name, such as bakery. Your account's prefix is added in front, giving a name like example_bakery.
  4. Leave User on Create a new user, and type a name under New user, such as shop.
  5. A strong Password is filled in for you. Copy it into a password manager, because your app's config file needs it.
  6. Leave Access on All privileges, then click Create database.
Create a database and a user for it

Done. You now have:

Item Example
Database name yourusername_bakery
User yourusername_shop
Password the one you saved
Host localhost

Do it step by step

  1. Open Account → Hosting → your site → Databases.
  2. Click New database, enter the name, set User to No user for now, and click Create database.
  3. Under Users and access, click New user, enter a name and password, and click Create user.
  4. In the Users and access grid, click the cell where the user's row meets the database's column. Choose All privileges, Read only, Custom, or No access, then click Save access.

Note: Names have length limits. A database name can be up to 64 characters and a user name up to 47, both counting the account prefix.

Use it in your app

<?php
// PHP (PDO)
$pdo = new PDO(
  'mysql:host=localhost;dbname=yourusername_bakery;charset=utf8mb4',
  'yourusername_shop',
  'your-password',
  [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
// Node.js (mysql2)
const mysql = require('mysql2/promise');
const db = await mysql.createConnection({
  host: 'localhost',
  user: 'yourusername_shop',
  password: process.env.DB_PASSWORD,
  database: 'yourusername_bakery',
});
# Python (PyMySQL)
import pymysql, os
db = pymysql.connect(
    host="localhost",
    user="yourusername_shop",
    password=os.environ["DB_PASSWORD"],
    database="yourusername_bakery",
    charset="utf8mb4",
)

For WordPress, set these in wp-config.php:

define( 'DB_NAME',     'yourusername_bakery' );
define( 'DB_USER',     'yourusername_shop' );
define( 'DB_PASSWORD', 'your-password' );
define( 'DB_HOST',     'localhost' );

Keep passwords out of public folders. See Set environment variables for apps.

Change a password or delete

Back in Databases: use Change password next to a user, or delete a database or user from its row. Deleting a database removes all its data. Take an export first. See Export a database.

If something goes wrong

Was this helpful?

Still stuck? Ask us and we'll walk you through it.