mysql基本操作

#访问控制

##登录mysql

mysql -u root -p

##查看所有用户

select user from mysql.user

##创建用户

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

##删除用户

注意必须明确给出该账号的主机名

drop user 'test'@'localhost';

##重命名用户

rename user 'test'@'localhost'to'foo'@'localhost';

##修改密码

set password for 'test'@'localhost'=password('hello');

#权限管理

##查看权限

show grants for 'test'@'localhost';

##授权

grant select(cust_id,cust_name)
    on mysql_test.customers
    to'zhangsan'@'localhost';--授予在数据库mysql_test的表customers上拥有对列cust_id和列cust_name的select权限

  

grant select ,update
    on mysql_test.customers
    to 'liming'@'localhost'identified by'123';--新建一个用户为liming,并授予其在数据库mysql_test的表customers上拥有select和update的权限

  

grant all
    on mysql_test.*
    to'zhangsan'@'localhost';--授予可以在数据库mysql_test中执行所有操作的权限

  

grant create user
    on *.*
    to'zhangsan'@'localhost';--授予系统中已存在用户zhangsan拥有创建用户的权限

##权限的转移

grant select,update
    on mysql_test.customers
    to'zhou'@'localhost'identified by'123'
    with grant option;

如果上面with子句后面跟的是

max_queries_per_hour count、 
max_updates_per_hour count、 
max_connections_per_hour count、 
max_user_connections count 
中的某一项,则该grant语句可用于限制权限

grant delete
    on mysql_test.customers
    to 'zhangsan'@'localhost'
    with max_queries_per_hour 1;--每小时只能处理一条delete语句的权限

##权限的撤销

revoke select 
    on mysql_test.customers
    from'zhangsan'@'localhost';--回收用户zhangsan在数据库mysql_test的表customers上的select权限

搬运自http://blog.csdn.net/ParanoidYang/article/details/61951265

原文地址:https://www.cnblogs.com/littleby/p/8481439.html