Create a MySQL database and user
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)
- Open Account → Hosting → your site → Databases.
- Click New database. Create a database and a user for it opens.
- Under Database name, type a name, such as
bakery. Your account's prefix is added in front, giving a name likeexample_bakery. - Leave User on Create a new user, and type a name under New user, such as
shop. - A strong Password is filled in for you. Copy it into a password manager, because your app's config file needs it.
- Leave Access on All privileges, then click Create database.
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
- Open Account → Hosting → your site → Databases.
- Click New database, enter the name, set User to No user for now, and click Create database.
- Under Users and access, click New user, enter a name and password, and click Create user.
- 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
- "Access denied for user": password typo or privileges missing. See Fix "Error establishing a database connection".
- "Unknown database": use the full prefixed name.
Still stuck? Ask us and we'll walk you through it.
