设置权限语句:grant 权限名(sqlserver和mysql不一样的,可以看手册知道,分所有的权限用all)on 库名(*表全部).表名(*表全部) to 要授权的用户名@"%"(%表示所有的IP,可以只些一个IP)identified by "密码";
mysql> create database c_t; Query OK, 1 row affected (0.28 sec)mysql> use c_t; Database changed mysql> show tables; Empty set (0.00 sec)mysql> create table a(id int not null); Query OK, 0 rows affected (0.00 sec)mysql> create table b(id int not null); Query OK, 0 rows affected (0.00 sec)mysql> create table c(id int not null); Query OK, 0 rows affected (0.01 sec)mysql> create table d(id int not null); Query OK, 0 rows affected (0.00 sec)mysql> show tables; +---------------+ | Tables_in_c_t | +---------------+ | a | | b | | c | | d | +---------------+ 4 rows in set (0.00 sec) mysql> grant all privileges on c_t.a to webuser@'%' identified by '123456'; Query OK, 0 rows affected (0.00 sec)mysql> grant all privileges on c_t.b to webuser@'%'; Query OK, 0 rows affected (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)mysql> \q Bye [root@localhost ~]# mysql -uwebuser -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 28230 Server version: 5.1.21-beta MySQL Community Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> use c_t; Database changed mysql> show tables; +---------------+ | Tables_in_c_t | +---------------+ | a | | b | +---------------+ 2 rows in set (0.00 sec)
to 要授权的用户名@"%"(%表示所有的IP,可以只些一个IP)identified by "密码";
mysql> create database c_t;
Query OK, 1 row affected (0.28 sec)mysql> use c_t;
Database changed
mysql> show tables;
Empty set (0.00 sec)mysql> create table a(id int not null);
Query OK, 0 rows affected (0.00 sec)mysql> create table b(id int not null);
Query OK, 0 rows affected (0.00 sec)mysql> create table c(id int not null);
Query OK, 0 rows affected (0.01 sec)mysql> create table d(id int not null);
Query OK, 0 rows affected (0.00 sec)mysql> show tables;
+---------------+
| Tables_in_c_t |
+---------------+
| a |
| b |
| c |
| d |
+---------------+
4 rows in set (0.00 sec)
mysql> grant all privileges on c_t.a to webuser@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)mysql> grant all privileges on c_t.b to webuser@'%';
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> \q
Bye
[root@localhost ~]# mysql -uwebuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28230
Server version: 5.1.21-beta MySQL Community Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> use c_t;
Database changed
mysql> show tables;
+---------------+
| Tables_in_c_t |
+---------------+
| a |
| b |
+---------------+
2 rows in set (0.00 sec)