Set special characters for password while creating a new MySQL user?


To set special characters for a password, use the following syntax −

create user 'yourUserName'@'yourHostName' identified by 'yourSpecialCharacterPassword';

Let us implement the above syntax in order to create a new user and set password with special characters −

mysql> create user 'Mike'@'localhost' identified by 'Mike_123456';
Query OK, 0 rows affected (0.35 sec)

Let us check the table where MySQL user and host is stored −

mysql> select user,host from MySQL.user;

This will produce the following output. The new user created successfully −

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| Bob              | %         |
| Charlie          | %         |
| Robert           | %         |
| User2            | %         |
| mysql.infoschema | %         |
| mysql.session    | %         |
| mysql.sys        | %         |
| root             | %         |
| @UserName@       | localhost |
| Adam Smith       | localhost |
| Chris            | localhost |
| David            | localhost |
| James            | localhost |
| John             | localhost |
| John Doe         | localhost |
| Mike             | localhost |
| User1            | localhost |
| am               | localhost |
| hbstudent        | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
+------------------+-----------+
21 rows in set (0.00 sec)

Updated on: 22-Aug-2019

340 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements