# Create a User Account

__*TiDB to create a user account*__

+ `CREATE USER 'test'@'127.0.0.1' IDENTIFIED BY '1234';    -'test':user_name is case sensitive  -'127.0.0.1':host_name can be a hostname or IP address`

+ `CREATE USER 'test'@'192.168.10.%';`

+ `CREATE USER 'test';`

-------------------------------------------------------------
There are two ways to add users:
- Create users and grant privilege through standard user-managed SQL statements, such as CREATE USER and GRANT.
- Authorize tables directly with INSERT, UPDATE, and DELETE operations

The first method is recommended. Modifications in the second way tend to lead to incomplete modify and are therefore not recommended.

For example: CREATE USER 'test'@'127.0.0.1' IDENTIFIED BY '1234';

After setting the login password, the auth_string is encrypted by TiDB and stored in the mysql.user table.

The user account name for TiDB consists of a user name and a host name. The syntax for the account name is 'user*name'@'host*Name'.
- user_name is case sensitive.
- Host*name can be a host name or an IP address. Wildcard characters% and are allowed in hostnames or IP addresses*. For example, a hostname named '%' can match all host, and '192.168.1.%' can match all host in a subnet.

The host supports fuzzy matching, for example:
CREATE USER 'test'@'192.168.10. %';

Allow the test user to log in from any host on the 192.168.10 subnet.

If no host is specified, the default is that all IPs can log in. If no password is specified, the default is empty:

CREATE USER 'test';

Equivalent to:

CREATE USER 'test'@'%' IDENTIFED BY ";

Please refer to: https://docs.pingcap.com/zh/tidb/stable/user-account-management