---
title: "MySQL User Creation: Stop Using Root and Set Passwords Correctly"
description: "Learn how to properly create dedicated MySQL users with least-privilege access instead of using root for applications. Includes best practices for host restrictions, password security, permission grants, and a practical checklist for securing MySQL databases in production environments."
image: "https://www.sethserver.com/static/images/create-a-new-user-1-1.webp"
---

# MySQL User Creation: Stop Using Root and Set Passwords Correctly

You know what I do right after I spin up a fresh MySQL box?

I create dedicated users. Then I stop using `root`.

Not because I'm paranoid. Because I like sleeping. And because I've watched "temporary" root access turn into "wait, why does the app user have DROP TABLE in production" more times than I want to count. Sleep is good. Panic at 3am is not.

This is boring work. It's also the kind of boring work that saves your weekend when something breaks at 2am and you need to figure out which service did what.

## Root is for setup, not for apps

`root` is a sledgehammer. It's fine for initial setup and emergencies. It's a bad default for:

- application connections
- data pipelines
- admin scripts you run half-awake
- anything that lives longer than an afternoon

The goal isn't to never mess up. The goal is to [build systems that catch you when you do](https://www.sethserver.com/startups/its-not-about-crushing-success-its-about-recovering-from-catastrophic-failure.html). Least-privilege DB users are part of that system.

## The one command you need (and the part people mess up)

Here's the basic syntax:

```sql
CREATE USER 'name'@'host.name' IDENTIFIED BY 'VerySecurePassword';
```

Three pieces matter:

1. **Username**: `'name'`
2. **Host**: `'host.name'` (or an IP, or `%`, more on that in a second)
3. **Password**: set by `IDENTIFIED BY`

That last part is not optional.

If you skip `IDENTIFIED BY`, you might create a user that can connect **without a password**. It depends on your auth plugin and server config, but why risk it?

So don't do this:

```sql
CREATE USER 'app'@'%';
```

I don't care if it works on your laptop. Plenty of terrible ideas work on laptops. Production is different.

## Picking the right host: don't use `%` unless you mean it

The host part controls where the user can connect from.

Common patterns:

- `'app'@'localhost'` for local services on the DB machine
- `'app'@'10.0.1.50'` for a single app server
- `'app'@'10.0.1.%'` for a subnet (still risky, but sometimes real life)
- `'app'@'%'` for anywhere (usually a mistake)

If you're moving fast at a startup and you don't know the final network yet, you can start broader and tighten later. Just do it on purpose. Put it on a checklist. Future-you is busy and cranky.

## Give permissions like you're paying for each one

Creating the user is step one. Step two is permissions.

A typical app user often needs something like:

```sql
GRANT SELECT, INSERT, UPDATE, DELETE
ON yourdb.*
TO 'app'@'10.0.1.50';
```

And then:

```sql
FLUSH PRIVILEGES;
```

(Yes, MySQL often applies grants without it now. I still run it because I like being boring and correct.)

Avoid handing out:

- `GRANT ALL`
- `DROP`
- `ALTER`
- anything global like `ON *.*`

Unless you're doing migrations and you *know* that's what you're doing. Even then, consider a separate "migration user" you only use during deploys.

## Passwords: stop making them "Summer2026!"

Strong passwords matter. I've seen databases get exposed through weird paths - a misconfigured security group here, a debug port someone left open there, a tunnel that was "just for testing" six months ago. Attackers don't need creativity. They need time.

I generate passwords with my own tool here:

[Secure Random Password Generator](https://www.sethserver.com/secure-random-password-generator.html)

Use whatever generator you trust. The point is: long, random, not reused, and stored in a real secret manager (or at least an environment variable that isn't committed to Git because someone got "helpful").

## My basic checklist after provisioning a DB

- create an app user with least privileges
- create an admin user for humans (not `root`)
- create a migration user if needed
- confirm backups exist and have been tested
- write down the grants so nobody has to guess later

None of this is exciting. But it works.

If you take one thing from this: **don't use root for your app, and always include `IDENTIFIED BY` when creating users.**

-Sethers


```json
{"@context": "https://schema.org", "@type": "BlogPosting", "headline": "MySQL User Creation: Stop Using Root and Set Passwords Correctly", "datePublished": "2020-12-01T00:00:00", "dateModified": "2026-03-18T23:41:37", "image": {"@type": "ImageObject", "url": "https://www.sethserver.com/static/images/create-a-new-user-1-1.webp", "width": 400, "height": 400}, "url": "https://www.sethserver.com/mysql/create-a-new-user.html", "author": {"@type": "Person", "name": "Seth Black", "url": "https://www.linkedin.com/in/seth-black-tx"}, "publisher": {"@type": "Organization", "name": "Sethserver", "logo": {"@type": "ImageObject", "url": "https://www.sethserver.com/static/images/PaperAirplane512.png"}}, "description": "Learn how to properly create dedicated MySQL users with least-privilege access instead of using root for applications. Includes best practices for host restrictions, password security, permission grants, and a practical checklist for securing MySQL databases in production environments.", "articleSection": "Technology"}
{"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{"@type": "ListItem", "position": 1, "name": "sethserver", "item": "https://www.sethserver.com/"}, {"@type": "ListItem", "position": 2, "name": "MySQL", "item": "https://www.sethserver.com/mysql/"}, {"@type": "ListItem", "position": 3, "name": "MySQL User Creation: Stop Using Root and Set Passwords Correctly", "item": "https://www.sethserver.com/mysql/create-a-new-user.html"}]}
```
