Adding a database user and connecting your site
Adding a database user and connecting your site
What you'll learn: how to add a database user and use it to connect your website or app.
What's a database user?
A database user is the username/password your app uses to read and write to a database. Every app needs one. You can have multiple users for the same database (for example, one with full access for the app itself, one with read-only access for a reporting tool).
Step 1 — Open the Databases page
Sidebar → Databases. Click Database users (or a similar tab).
Step 2 — Create the user
- Click New user.
- Pick a username (lowercase, no spaces — like
mysite_admin). The panel may add a prefix automatically — that's fine. - Pick a strong, random password. Use a password manager.
- Click Create.
Step 3 — Assign the user to a database
Each user has to be linked to the database(s) it can access.
- From the Databases tab, click your database.
- Click Add user.
- Pick the user you just created.
- Choose privileges. For most apps, All privileges is correct. For a read-only role, pick SELECT only.
- Click Save.
[screenshot here: assigning a user to a database]
Step 4 — Connect your app
In your app's config file (or installer screen), enter:
- Host:
localhost - Database name: the full name (with the prefix the panel added)
- Username: the full username (also with prefix)
- Password: the one you set
- Port:
3306(only fill this in if asked)
For WordPress, the file is wp-config.php and the lines look like:
define( 'DB_NAME', 'youraccount_mysite' );
define( 'DB_USER', 'youraccount_admin' );
define( 'DB_PASSWORD', 'your-strong-password' );
define( 'DB_HOST', 'localhost' );
Save the file, reload your site — if it loads without errors, you're connected.
Tips
- Different password for each app. If one app's database password leaks, it shouldn't compromise another.
- Don't store the password in source control. If your app's code is in Git, keep the database password in a separate file (like
.env) that isn't committed. - Keep a copy in your password manager. You'll need it again next time you upgrade or migrate the app.
If something goes wrong
- "Access denied for user" — the user isn't assigned to that database, or the password is wrong, or the username is missing the prefix.
- "Unknown database" — you typed the name without the prefix. Use the full name shown in the Databases page.
- "Can't connect to MySQL server on 'host'" — host should be
localhost, not your domain.
Related articles