# How to create and delete users in MySQL > Part of Prisma's Data Guide. The complete index is at https://www.prisma.io/dataguide/llms.txt. Learn how to create MySQL users, delete users, and manage user access with this easy-to-use guide. Canonical URL: https://www.prisma.io/dataguide/mysql/short-guides/creating-deleting-users Authors: Alex Emerich Content revision: 91b5ea3b95a0824bcd0e0d61f68d6121c6e45039fde2b5f874c4c65eec29030e Source revision: b6716699f6439c3ba6ae3bf7116b7da84963c978 Last updated: 2026-09-29 ## Introduction More often than not, when working with a database you will need to be able to create and delete users. Whether working in a team that has multiple members needing access to the database or creating and deleting test users to simulate database privileges, knowing how to add and remove database users is important. In this short guide, we will cover the basics of creating and deleting database users in MySQL. These commands will have you ready to get started on granting database access and establish a foundation for future [role management](https://www.prisma.io/dataguide/mysql/authentication-and-authorization/role-management). ## How do you create MySQL users? Creating users in MySQL is key for collaborating with others and for testing access rights and privileges. It is important to note that in order to create users you must login with a user with the privileges described in the [prerequisites](https://www.prisma.io/dataguide/mysql/authentication-and-authorization/user-management-and-authentication#prerequisites). ### Basic syntax The basic syntax for creating a new user is relatively simple. You use the `CREATE USER` command, specify the user and host for the new account, and set a password for it: ```sql CREATE USER ''@'' IDENTIFIED BY ''; ``` This creates a new user account and assigns a password for the account at the same time. ### How do you create a user with a password? The `IDENTIFIED BY` clause in the example above configures [authentication](https://www.prisma.io/dataguide/intro/database-glossary#authentication) for the new account by setting its password. The clause is optional, but you should always include it (or configure another authentication method, as shown below). An account created without it has no password, so anyone who connects from a matching host can log in as that user without one. The host part of the account name controls where the user can connect from. Use `localhost` for a user that connects from the database server itself, or the specific host name or IP address that the user connects from. The `%` wildcard matches any host, so only use it for accounts that really need to connect from anywhere. To assign or change a password after the account exists, use the `ALTER USER` command, as described in our guide to [managing users and authentication](https://www.prisma.io/dataguide/mysql/authentication-and-authorization/user-management-and-authentication#how-do-you-change-the-password-for-a-mysql-user). ### How do you give a new user access to a database? A new account can log in, but it can't read or change the data in your databases until you grant it privileges. Grant only the privileges the account needs, on only the databases it needs. For example, to create an account for an application that reads and writes the data in an `app_db` database from the same machine: ```sql CREATE USER 'app_user'@'localhost' IDENTIFIED BY ''; GRANT SELECT, INSERT, UPDATE, DELETE ON app_db.* TO 'app_user'@'localhost'; ``` Running `GRANT` requires the `GRANT OPTION` privilege as well as the privileges you are granting, which an administrative account like `root` has. `app_user` can now query and modify the rows in `app_db`'s tables, but it can't create or drop tables, and it can't access any other database: ```text mysql> USE other_db; ERROR 1044 (42000): Access denied for user 'app_user'@'localhost' to database 'other_db' mysql> CREATE TABLE app_db.extra (id INT); ERROR 1142 (42000): CREATE command denied to user 'app_user'@'localhost' for table 'extra' ``` You can learn more in our guide to [managing privileges in MySQL](https://www.prisma.io/dataguide/mysql/authentication-and-authorization/privilege-management). ### How do you create a user with Unix socket authentication? While password authentication is the most common authentication method for most users, it's not the only option. MySQL provides many different internal and external authentication mechanisms that you can configure your user accounts to use. As an example, we'll configure a new account using Unix socket authentication. Unix socket authentication can be used in Linux or Unix-like environments so that an account on the operating system is given access to the same account name within MySQL without further authentication. In this configuration, the [MySQL administrator](https://www.prisma.io/dataguide/intro/database-glossary#database-administrator) knows that user accounts on the operating system are tightly controlled. So if there is a `mary` user on the operating system, they will be able to login to the `'mary'@'localhost'` account within MySQL if Unix socket authentication is the defined authentication mechanism. Let's configure this now. Socket authentication requires the `auth_socket` plugin, so first load the plugin by typing: ```sql INSTALL PLUGIN auth_socket SONAME 'auth_socket.so'; ``` Next, create a user account that matches a user account you have on your operating system. For this example, we'll use the `mary` account we discussed above. If you don't use a name that matches one of your operating system names, you won't be able to authenticate using this user. To create the user with socket authentication, we need to use the `IDENTIFIED WITH` clause (different than the `IDENTIFIED BY` clause used earlier) to specify the authentication plugin to use: ```sql CREATE USER 'mary'@'localhost' IDENTIFIED WITH auth_socket; ``` Now, you should be able to authenticate to the `'mary'@'localhost'` MySQL user from the `mary` user on your operating system. When logged in as `mary`, connect to the database without providing any username or password: ```shell mysql ``` You should be signed in automatically through the Unix socket authentication you configured. ## How do you delete MySQL users? Keeping user accounts around that no longer serve a purpose is a security risk. You can remove accounts easily with the `DROP USER` command. The basic syntax looks like this: ```sql DROP USER ''@''; ``` So to delete the 'mary'@'localhost' user, you would type: ```sql DROP USER 'mary'@'localhost'; ``` If you try to delete a user that does not exist, you will receive an error: ```text ERROR 1396 (HY000): Operation DROP USER failed for 'mary'@'localhost' ``` To avoid this, you can add the `IF EXISTS` clause before the account name. If the user exists, it will be deleted. If it does not, only a warning will be given: ```sql DROP USER IF EXISTS 'mary'@'localhost'; ``` ```text Query OK, 0 rows affected, 1 warning (0.00 sec) ``` ## Conclusion In this quick guide, we covered the basics of creating and deleting users for MySQL databases as well as some additional options. Once your users are created, we have additional informative articles diving deeper in [user role management](https://www.prisma.io/dataguide/mysql/authentication-and-authorization/role-management) in MySQL as well as [user authentication](https://www.prisma.io/dataguide/mysql/authentication-and-authorization/intro-to-authn-and-authz).