How to Create and Manage MySQL Users
Imagine a library where anyone can come in and make edits to the books at any time.
You come in to check out Lord of the Rings, but suddenly, instead of a timeless tale of friendship and courage in the face of all-consuming evil, it’s quite the opposite.
Someone has rewritten Frodo and Sam’s heroic journey to Mordor, making them give up on saving Middle Earth, opting instead to open a jewelry store in Bree. Their first customer? Sauron. And wouldn’t you know it, he’s shopping for a ring.
As for Aragorn, Legolas, and Gimli? Let’s just say whoever’s edited the story is very into fan fiction. We’ll leave it at that.
Your website is like that library, and the database that powers it is like all the books in it. If you give just about anyone access to come in and make changes, you could end up with a Lord of the Rings rewrite situation — but so much worse because it could put your entire site (and all its data) at risk.
Database
A database is a collection of information accessible to computers. Databases are used to store information such as customer records, product catalogs, and financial transactions.
Read More
That’s why you need to control who can see, access, and modify your data to keep your site secure and running smoothly.
This post will walk you through the basics of MySQL user management, from creating user accounts to assigning and modifying permissions.
Ready to dive in? Let’s get started!
What is a MySQL Database?
A MySQL database is a structured collection of data stored electronically and managed using the MySQL Database Management System (DBMS).
MySQL, an open-source relational database management system, uses Structured Query Language (SQL) for accessing, managing, and manipulating the data.
A MySQL database is designed to handle everything from a single row of information to large datasets comprising millions of rows. It’s built to store data in tables, which are organized into rows and columns. Each table in a MySQL database serves a specific purpose, holding data relevant to different aspects of your site or web application.
MySQL is well known for being reliable and easy to use. Web developers across industries use it for web applications, logging applications, data warehousing, and more. Whether you’re storing user information, product catalogs, or transaction records, MySQL is robust and scalable and can likely meet your database management needs.
Pro tip: Need to migrate or connect a MySQL database to your DreamHost site? Find an easy-to-follow tutorial in our Knowledge Base.
MySQL User Accounts Explained
MySQL user accounts are essential for managing access to your database. Each user account in MySQL can be given specific permissions that dictate what actions the user can perform. This granular control helps maintain the security and integrity of your data.
The Role of the Root User
When you first install MySQL, a default user account called root is created.
The root user has full administrative privileges, meaning they can perform any action on the database, including creating and deleting databases, adding and removing users, and granting or revoking permissions.
While the root user is powerful, we don’t recommend relying solely on this account for all tasks. Using the root account for everyday operations poses a significant security risk.
If anyone gains unauthorized access to this account, they’ll have control over your database.
Why Create New Users?
For better security and to streamline database management, the best practice is to create specific user accounts for different purposes.
For example, you might create separate accounts for developers, administrators, and application processes, giving each type of account only the necessary permissions they need to perform their tasks. This way, you minimize the risk of accidental or malicious actions that could affect your database’s integrity and security.
Creating new user accounts allows you to:
- Improve database and site security: Limit access to sensitive data and critical operations by assigning only the necessary permissions to each user.
- Better organize roles: Clearly define roles and responsibilities within your team by giving everyone the appropriate level of access to tasks they need to do.
- Make it easier to manage your database: Easily track and manage user activities, making it simpler to audit changes and identify issues.
How to Manage Your MySQL Users (Two Methods)
We’ll cover two primary methods to manage your MySQL users: using MySQL directly, and using the DreamHost panel. In the end, which method you use will depend on your comfort level with command-line tools and your specific requirements.
Managing Users With MySQL
To manage MySQL users directly through MySQL, you’ll need to have MySQL installed on your system.
This involves downloading the MySQL software from the official MySQL website, installing it, and configuring it according to your operating system’s requirements.
Once installed, you can interact with your MySQL database using the MySQL command-line client.
Nerd Note: Most of the following commands can only be used on dedicated servers. You can check out our Knowledge Base for more information.
To install MySQL, follow these steps:
Once you have MySQL set up, you can create, manage, and delete user accounts using SQL commands.
This method gives you a high level of control and flexibility, but it does require you to be familiar with SQL syntax and command-line operations (which we’ll cover in more detail below).
How to Create a MySQL User Account
Nerd Note: Whenever a password is assigned via command prompt, it’s good practice to clear the terminal history to reduce the risk of someone stumbling across a password.
How to Grant Privileges for a MySQL User
How to See Privileges for a MySQL User
How to Modify Permissions for a MySQL User
If you need to completely change a user’s privileges, it might be easier to revoke all their existing privileges first and then grant the new set of permissions. To revoke all privileges from a user, use: REVOKE ALL PRIVILEGES, GRANT OPTION FROM ‘newuser’@’localhost’;
Then, grant the new set of privileges as needed: GRANT SELECT, UPDATE ON exampledb.* TO ‘newuser’@’localhost’;
Don’t forget to flush the privileges after making these changes: FLUSH PRIVILEGES;
How to Delete a MySQL User
How to Show Users for a MySQL Database
Viewing all users in your MySQL database is a useful way to manage and audit user accounts. Then you’ll know who’s got access to your database and what their permissions are.
If you’re familiar with MySQL commands, you might think there’s a SHOW USERS command — similar to the SHOW DATABASES or SHOW TABLES commands you probably already know and use. However, SHOW USERS doesn’t exist.
So how do you see all your database users? Follow these steps.
Managing Users With DreamHost
If the idea of using command-line tools seems daunting, the DreamHost panel offers a user-friendly alternative for managing MySQL users.
The DreamHost panel is a web-based interface that simplifies database management tasks, so you don’t have to use command prompts.
For detailed tutorials on accessing your database, adding and deleting users, managing privileges, and more, visit our Knowledge Base page for MySQL databases.
And if you’re looking for reliable managed hosting for your website that not only makes database management straightforward with an intuitive control panel, but also offers free migration, 24/7 support, and uptime guarantees — you need DreamHost.
Check out our affordable hosting plans and see why millions of people and businesses choose us!
Dedicated Hosting
Ultimate in Power, Security, and Control
Dedicated servers from DreamHost use the best hardwarernand software available to ensure your site is always up, and always fast.
See More