Skip to main content
.com domains from $2.99 — free WHOIS privacy on every name

Database setup · Beginner · 5 minutes

How to create a MySQL database — Three Objects, Four Connection Values, One Grant

The installer says access denied, the password is definitely right, and a grant that was never applied looks exactly like a typing mistake.

The short answer

Creating a database is three objects, not one: the database, a user, and a grant tying that user to that database. Miss the third and the application reports access denied for user — which reads exactly like a wrong password and is not one.

Then record four values, because every installer form asks for the same four: host, database name, username and password. Use localhost when the application runs on the same account, and understand that localhost and 127.0.0.1 are different hosts as far as MySQL grants are concerned.

By the HostingFast team · Reviewed 24 August 2026

Beginner

Difficulty grade

5 minutes

Time budget

5

Stages

24/7

Engineer cover

Five minutes with the wizard, or fifteen minutes of debugging without it. The wizard exists because the grant is the step that goes missing when the three objects are created separately.

The section on localhost against 127.0.0.1 is the one worth reading even if you have done this a hundred times, because it explains a class of access-denied error that looks impossible.

Three objects, not one

MySQL keeps databases and users in separate namespaces, and permission is a third thing that references both. cPanel's wizard walks all three in order — create database, create user, assign privileges — which is precisely why it is the recommended route rather than the beginner's route.

Create them individually and the failure is silent until the application tries to connect. There is no warning that a user exists with no rights anywhere; you find out from a stack trace that says access denied and looks like bad credentials.

localhost is not 127.0.0.1

To MySQL, localhost means connect over the Unix domain socket, and 127.0.0.1 means open a TCP connection to the loopback interface. They are two different transports, and grants are recorded per user and per host — so a user granted at 'localhost' is legitimately refused when the same application connects to 127.0.0.1.

The socket is also the faster of the two, because it skips the TCP stack entirely. On a single-account application there is no reason to use anything else, and DB_HOST should read localhost unless something specifically requires otherwise.

Naming, charset, and the prefix you do not control

cPanel prefixes both database and user with your account name, so the visible half is the part you choose. Make it describe the contents — shop, crm, staging — because db1 and test tell you nothing in six months and you will not be the only person reading it.

Create the database as utf8mb4 with a utf8mb4 collation. The older utf8 in MySQL stores a maximum of three bytes per character, which silently truncates four-byte characters including emoji, and retrofitting the charset onto a populated table is considerably more work than choosing it now.

The four connection values, and where remote access fits

Host, database name, username, password. Those four answer every installer form ever written, and they belong in your password manager and in the application's configuration file rather than in anybody's memory.

External access is off deliberately. Remote MySQL will admit a specific address when a desktop client or a reporting tool genuinely needs it, but a connection from your laptop crosses the internet on every query, so a tool that would run in a second locally can take a minute over that link. Prefer phpMyAdmin or an SSH tunnel.

Driving a hosting account through the cPanel dashboard

The platform these values were tested against

Every screen and value here was confirmed on the stack we operate: cPanel's database wizard, the same account prefixing, the same MySQL service. Nothing is generalised from elsewhere.

Already hosted somewhere slower? We migrate the whole site free, usually within 24 hours, and it keeps serving visitors throughout.

  • Three objects, one wizard
  • Socket against TCP, explained
  • Charset chosen, not defaulted
  • Engineers on shift at any hour

Why HostingFast

Standard on every plan

Three objects, one pass

Database, user and grant — the wizard does all three, which is exactly why the wizard wins.

localhost against 127.0.0.1

Socket versus TCP, and why a grant for one host refuses a connection from the other.

Charset stated

utf8mb4 so four-byte characters store correctly rather than truncating the row that contains them.

Names that still make sense later

The account prefix is fixed; the half you choose should describe what is inside the database.

The four connection values

Host, database, user, password — the answers to every installer form you are ever going to meet.

Remote access understood

Off by default, enabled deliberately, with the latency cost of a round trip per query made explicit.

Quick Start

From order to online

  1. 1

    Use the database wizard

    It performs the three steps in order and cannot leave the grant out. Manual creation is the only way to end up with a user that exists and can do nothing.

  2. 2

    Name it so it is legible in six months

    The account prefix is added for you. Your half should say what lives in there — shop, crm, staging — rather than db1.

  3. 3

    Create it as utf8mb4

    Four-byte characters store correctly, emoji included. Changing the charset after the tables have data is a migration rather than a setting.

  4. 4

    Generate the password into a manager, then the config file

    Database credentials are infrastructure, not something to remember. Generate, store, paste into the application's configuration.

  5. 5

    Grant all privileges, then record the four values

    The application needs full authority over its own database. Note host, name, user and password, and set DB_HOST to localhost unless something demands TCP.

Built In

Loaded onto every plan

  • NVMe SSD storage on every tier, not just the expensive ones
  • cPanel — the panel most of the industry already automates against
  • Daily backups with restores you trigger yourself from the panel
  • PHP version set per site from the panel, not per server
  • SSH, Git and Composer on the developer-focused plans
  • LiteSpeed caching in the server itself, not bolted on by plugin
  • Staging environments for testing before anything ships
  • 99.9% uptime as the target, monitored around the clock
  • One-click installs for WordPress and 400+ other applications
  • Engineers on shift every hour of every day, not a queue that opens at nine

Frequently Asked

What people ask us most often

Why do I get access denied when the password is definitely correct?

Two likely causes and neither is the password. Either the grant was never applied, so the user exists with no rights on that database, or the grant is recorded for a different host than the one the application connects from — localhost against 127.0.0.1 being the classic pair. Check the privileges screen before touching the credential.

Should DB_HOST be localhost or 127.0.0.1?

localhost, when the application runs on the same hosting account. MySQL reads localhost as the Unix socket, which skips the TCP stack and is marginally faster, and it is the host cPanel records the grant against. Use 127.0.0.1 only when a library genuinely cannot speak socket, and grant for that host explicitly if you do.

Which protocols do mailboxes speak?

Webmail runs in any browser, and every mailbox also speaks IMAP, POP and SMTP — so the mail app on your phone, the client on your desktop and webmail all stay in sync, showing the same messages in the same state.

How does billing and auto-renewal work?

You pay by credit or debit card through a secure checkout, and renewals bill at the same rate as your original order. Every invoice lives in your client area, and auto-renewal switches off with a toggle in your account — no phone call required.

Keep reading

Changing hosts? Run through our checklist first.

A straightforward sequence for a switch your visitors never feel: which files move first, how to shift email across without losing a single message, the right moment to repoint DNS, and the two mistakes behind almost all the downtime we get asked to rescue.

You'll get the checklist email, then occasional pointers on keeping a site running fast. Unsubscribe the moment you want out — the privacy policy covers the rest.

Put the database on NVMe.

NVMe storage on every tier, daily backups you restore yourself, and engineers on shift at any hour of the night.

View Secure Hosting plans