# How to create a new user and manage permissions in MySQL?

{% embed url="<https://youtu.be/wphy3bb_25g>" %}

### Overview <a href="#howtocreateanewuserandmanagepermissionsinmysql-overview" id="howtocreateanewuserandmanagepermissionsinmysql-overview"></a>

In this tutorial, we will learn how to create and manage new and existing users using CLI (command line interface). These commands will function on any platform.

### Prerequisites <a href="#howtocreateanewuserandmanagepermissionsinmysql-pre-requisite" id="howtocreateanewuserandmanagepermissionsinmysql-pre-requisite"></a>

There are certain prerequisites that need to be met before you begin:

* An Ubuntu 20.04 server&#x20;
* MySQL installed on your Ubuntu system
* Knowledge of CLI

### Get Sarted

1\. Follow these steps to setup a password-based access by creating an account to login:

```
sudo mysql
```

2\. Check access levels of existing accounts by using the below command:

```
SELECT user,authentication_string,plugin,host FROM mysql.user;
```

3\. To setup a password for root account, use the below command.

```
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
```

Or if you have an older version try:

```
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
```

4\. Now, check the list of existing accounts to confirm.

```
SELECT user,authentication_string,plugin,host FROM mysql.user;
```

5\. Follow these steps for making a separate user access than root.

```
sudo mysql
```

Or if you have a password setup, use:

```
mysql -u root -p
```

6\. Type this command to create a user.

```
CREATE USER 'john'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_password';
```

Again, if you have an older version, try:

```
ALTER USER 'john'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
```

7\. To grant suitable privileges to your user, type the following command:

```
GRANT ALL PRIVILEGES ON *.* TO 'john'@'localhost' WITH GRANT OPTION;
```

8\. Exit mysql.

```
exit
```

### Conclusion <a href="#howtocreateanewuserandmanagepermissionsinmysql-conclusion" id="howtocreateanewuserandmanagepermissionsinmysql-conclusion"></a>

In this tutorial, we have created a new user and granted privileges to the user in MySQL client. These commands will work on any operating system and let you manage the user in MySQL.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acecloud.ai/knowledge-base/tutorials/how-to-create-a-new-user-and-manage-permissions-in-mysql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
