码迷,mamicode.com
首页 > 数据库 > 详细

mysql - 语法

时间:2019-05-04 09:48:21      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:mit   ima   roc   插入   分析   生效   insert   for   ges   

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‘,‘zs@sina.com‘,‘1980-12-04‘);
insert into users(id,name,password,email,birthday) values(2,‘lisi‘,‘123456‘,‘lisi@sina.com‘,‘1981-12-04‘);
insert into users(id,name,password,email,birthday) values(3,‘wangwu‘,‘123456‘,‘wangwu@sina.com‘,‘1979-12-04‘);
select * from users;

mysql - 语法

标签:mit   ima   roc   插入   分析   生效   insert   for   ges   

原文地址:https://www.cnblogs.com/ccdat/p/10807515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!