How can we create a MySQL user account by omitting the hostname?

MySQLMySQLi Database

If we omit the hostname part of the user account, MySQL will accept it and allow the user to connect from any host. Its syntax would be as follows −

Use mysql;
CREATE USER user_name IDENTIFIED BY password;

Here,

  • user_name is the name of the user we wish to take account of.
  • Password is the password we wish to make for user_account. With the help of this password, MySQL server will identify this user.

Example

In the given example we are creating a user ‘REMOTE’ by omitting the host name.

mysql> CREATE USER remote identified by 'password123';
Query OK, 0 rows affected (0.00 sec)

The user ‘Remote’ can connect to a server by any host.

mysql> SHOW GRANTS FOR remote@'%';
+------------------------------------+
| Grants for remote@%                |
+------------------------------------+
| GRANT USAGE ON *.* TO 'remote'@'%' |
+------------------------------------+
1 row in set (0.00 sec)

The user can be created by omitting host name as well as password. It can be understood with the help of the following example in which we have created the user ‘hello’

mysql> Create user hello;
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for hello@'%';
+-----------------------------------+
| Grants for hello@%                |
+-----------------------------------+
| GRANT USAGE ON *.* TO 'hello'@'%' |
+-----------------------------------+
1 row in set (0.00 sec)
raja
Published on 20-Feb-2018 17:48:04
Advertisements