mysql - 语法

use mysql; -- 用户信息都存储在mysql库中
select user from user;
create user juny identified by 'juny'; -- drop user juny
set password for juny=password('123456');
show grants for juny;
grant select,insert,update,delete on test.* to juny; -- 分配权限用 grant,回收用 revoke,修改权限后要其他用户重新登录才能生效
flush privileges;
revoke select,insert,update,delete on test.* from juny;

select version();
show databases;
use test;
show tables from test;
show columns from users; -- describe users
analyze table users; -- 分析表字段是否正常
check table users; -- 检查表是否正常
optimize table users; -- 当删除大量数据后收回表空间,优化表的性能
flush logs;
show processlist; -- 查看哪些进程/线程占用较多执行时间,可用kill命令终止相应进程
-- 在写存储过程批量插入大量数据时,应该关闭自动提交,即:先 start transaction,然后准备好数据后再 commit;
start transaction;
rollback;
commit;

explain select distinct name,email from users;
select distinct name,email from users;
select name from users limit 0,2;
select name from users where name='LISI'; -- mysql默认不区分大小写,字段名、字段值
select name from users where name is not NULL;
select name, email from users order by name desc, email desc;

create table users(
id int,
name varchar(40),
password varchar(40),
email varchar(60),
birthday date,
primary key(id)
)engine=innodb,default charset=utf8;
insert into users(id,name,password,email,birthday) values(1,'zhansan','123456','[email protected]','1980-12-04');
insert into users(id,name,password,email,birthday) values(2,'lisi','123456','[email protected]','1981-12-04');
insert into users(id,name,password,email,birthday) values(3,'wangwu','123456','[email protected]','1979-12-04');
select * from users;

猜你喜欢

转载自www.cnblogs.com/ccdat/p/10807515.html
今日推荐