# Create MySQL Users Accounts and Grant Privileges

> Those who write survive.........

<br>

### Creating MySQL account

```
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
```

* To allow connections from other hosts, specify **IP Address** in place of **localhost**
* To allow connections from all hosts, use **'%'** wildcard

<br>

### Setting user privileges with grant command

<br>

#### Setting user privileges

```
mysql> GRANT ALL PRIVILEGES ON dbname.table TO 'userID'@'host' IDENTIFIED BY 'password';
```

#### Setting access privileges to all databases and tables

```
mysql> GRANT ALL PRIVILEGES ON *.* TO userID@host IDENTIFIED BY 'password';
```

#### Grant privileges to all databases and tables and allow local and remote connections

```
mysql> GRANT ALL PRIVILEGES ON *.* to userID@'%' IDENTIFIED BY 'password';
```

#### Apply configured privileges

```
mysql> FLUSH PRIVILEGES;
```

* Must run this to apply!

#### Remove privileges

```
mysql> REVOKE ALL ON dbname.table FROM userID@host
```

#### View privileges

```
mysql> SHOW GRANTS FOR userID@host
```


---

# 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://chloe-codes1.gitbook.io/til/db/db-101/08_create_mysql_users_accounts_and_grant_privileges.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.
