第一种方法:
root@host# mysql -u root -p
Enter password:*******
mysql> use mysql;
Database changed
mysql> INSERT INTO user
(host, user, password,
select_priv, insert_priv, update_priv)
VALUES ('localhost', 'guest',
PASSWORD('guest123'), 'Y', 'Y', 'Y');
Query OK, 1 row affected (0.20 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0.01 sec)
第二种方法:
mysql> use mysql;
Database changed
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON TESTDB.*
-> TO 'testuser'@'localhost'
-> IDENTIFIED BY 'test123';
mysql> FLUSH PRIVILEGES;
这种方法是赋予全部权限:
<span style="font-size:24px;">mysql> use mysql;
Database changed
mysql> GRANT ALL PRIVILEGES
-> ON TESTDB.*
-> TO 'testuser'@'localhost'
-> IDENTIFIED BY 'test123';
mysql> FLUSH PRIVILEGES;
查询用户:
mysql> SELECT host, user, password FROM user WHERE user = 'guest';
mysql> SELECT host, user, password FROM user;
注意:在注意需要执行 FLUSH PRIVILEGES 语句。 这个命令执行后会重新载入授权表。 如果你不使用该命令,你就无法使用新创建的用户来连接mysql服务器,除非你重启mysql服务器。