...

/

Creating Users/Accounts

Creating Users/Accounts

Learn about creating and managing secure MySQL user accounts with proper syntax, host restrictions, and password setup.

Imagine our OnlineStore is growing rapidly. We’ve hired a new data analyst to look at sales trends and an inventory manager to keep track of product stock. We certainly don’t want to give them the main administrator password for the database! That would be like giving everyone the keys to the entire store, including the cash registers and the manager’s office. Instead, we need a way to create specific identities or accounts for each person or application that needs to interact with our database, and later, we’ll define exactly what each identity is allowed to do. This is where creating user accounts comes in, forming the bedrock of database security and controlled access.

By the end of this lesson, we’ll be able to:

  • Understand why creating separate user accounts in MySQL is so important.

  • Learn the correct syntax to create new users.

  • Define where users can connect from by specifying hostnames.

  • Set secure initial passwords for these new accounts.

  • Check which users already exist on our MySQL server.

Let’s get started on how we can manage who gets access to our database.

The importance of creating user accounts

Before we talk about how to do it, let’s think about why. Why should we set up separate user accounts? Why not just use one or two accounts for everyone?

  1. Security through Scrutiny (Principle of least privilege): This is a big one. Not everyone needs access to everything. A data analyst might need to read sales data, but they shouldn’t be able to change product prices or delete customer records. By creating distinct user accounts, we can later grant each user only the permissions absolutely necessary for their job. This minimizes potential damage, whether accidental or intentional. If an account with limited access is compromised, the scope of the breach is also limited.

  2. Accountability and auditing: When everyone uses a shared account, it’s impossible to tell who did what. If a critical piece of data gets deleted or changed incorrectly, how would we trace it ...