How can we create user accounts in MySQL database server?

As we know that, MySQL database server is having the user table in MySQL database which is used to store the user accounts so by using MySQL database we can create user accounts in MySQL database server. There must be two things while creating the new user account, one is the username and other is the hostname which is after @ character. The syntax for creating the user account is as follows −


Use mysql;
CREATE USER user_account IDENTIFIED BY password;

Here user_account is the name of the user we wish to take account of. It can be like username@hostname.

The password is the password we wish to make for user_account. With the help of this password, MySQL server will identify this user.


In the example below we are creating a user named abcd@localhost under user table of MySQL database −

mysql> use mysql
Database changed
mysql> create user abcd@localhost identified by 'password123';
Query OK, 0 rows affected (0.04 sec)

The query below will give us the privileges for the new user account abcd@localhost.

mysql> SHOW GRANTS FOR abcd@localhost;
| Grants for abcd@localhost                |
| GRANT USAGE ON *.* TO 'abcd'@'localhost' |
1 row in set (0.01 sec)