一、关于用户权限 1.基本知识(1)查看当前用户下的所有数据库:show databases; 切换到数据库:use dbname; 查看当前数据库下的所有表: show tables; 查看某个用户的权限信息: show grants for root@'localhost';(2)创建用户: create user 'username'@'host' identified by 'passwd' username:创建的用户名 host : 用户所能登录的主机,本地为localhost,登录所有主机为%; passwd: 用户的密码; (3)授权用户: grant all privileges on *.* to smith@'localhost' identified by 'smith123' WITH GRANT OPTION; flush privileges; 说明: all privileges表示授予所有权限,也可以是select,update,insert,delete等。 smith:创建的用户名,smith123为密码,也可以是空密码。 *.* 表示在所有数据库的所有表都可以登录。前一个*指定数据库的,后一个*指定表的。 localhost表示允许该用户登录的主机为本机,%表示所有的主机都能登录。 flush privileges:刷新权限; WITH GRANT OPTION:权限传递,就是我能把权限传递给第三方; (4)设置和修改用户密码 修改当前登录用户的密码:SET PASSWORD =PASSWORD("newpassword"); 修改非当前登录用户的密码:SET PASSWORD FOR 'username'@'host'=PASSWORD("newpassword"); (5)撤销用户权限 语法:revoke privileges on databasename.tablename from 'username'@'host'; privileges可以为select,update,indert,delete,drop等权限; 例如:撤销smith的删除权限 revoke delete on *.* from 'smith'@'localhost'; (6)删除用户 语法: drop user 'username'@'host'; 例如:删除smith用户 drop user 'smith'@'localhost';(7)显示当前登录用户:select user(); 2. 3. 4. 二、关于查询SQL 1.左连接select * from table1 a LEFT JOIN table2 b ON a.id=b.id; 说明:左连接会显示table1表和table2表共有的数据以及table1表中所有的数据; 2.右连接select * from table1 a RIGHT JOIN table2 b ON a.id=b.id;
说明:左连接会显示table1表和table2表共有的数据以及table2表中所有的数据; 3.