Tuesday 27 December 2011

Creating a User Without a Password in MySQL

I'm not sure why you would want to do this but you can create a MySQL user without a password:
 
UNIX > mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9972
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> create user barney;
Query OK, 0 rows affected (0.00 sec)
 
mysql> select user, host, password
    -> from mysql.user
    -> where user = 'barney';
+--------+------+----------+
| user   | host | password |
+--------+------+----------+
| barney | %    |          |
+--------+------+----------+
1 row in set (0.00 sec)
 
mysql> exit
Bye
UNIX >
 
A user without a password can logon without using –p:
 
UNIX > mysql -u barney
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9981
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> exit
Bye
UNIX >
 
And if he does include a –p, he can just press Enter when prompted to supply a password:
 
UNIX > mysql -u barney -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9982
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> exit
Bye
UNIX >
 
Dropping a user without a password is carried out in the usual way:
 
UNIX > mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10016
Server version: 5.0.67 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> drop user barney;
Query OK, 0 rows affected (0.00 sec)
 
mysql>

No comments: