日期:2014-05-16  浏览次数:20664 次

mysql创建用户、授权使用数据库、删除用户之各两种方法解决
使用root登陆mysql;

创建用户并授权使用数据库方法一
mysql> use mysql
Database changed

mysql> insert into user(Host,User,Password) values("localhost","little_bill",password("1234"));
Query OK, 1 row affected, 3 warnings (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

E:\>mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.41-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database little_billDB;
Query OK, 1 row affected (0.03 sec)

mysql> grant all privileges on little_billDB.* to little_bill@localhost identified by '1234';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye


删除用户方法一
mysql> use mysql
Database changed

mysql> DELETE FROM user WHERE User="little_bill" and Host="%";
Query OK, 1 row affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye


创建用户并授权使用数据库方法二
使用root账户登录
mysql> CREATE USER 'little_bill'@'%' IDENTIFIED BY  '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE DATABASE IF NOT EXISTS  `little_billDB`;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON  `little_billDB` . * TO  'little_bill'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye


删除用户方法二
mysql> drop user 'little_bill'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)