获取当前时间:select now();
有价值的数据删除:update 表名 set is_delete = 'Y';
注释:# /*....*/
查看数据存储引擎:show engines;
查看表结构:describe 表名;
删除表数据(能使auto_crement重新开始计数,不同于delete):truncate 表名;
事务:transaction
关闭自动提交:set autocommit = 0
开始事务:
begin;
...;
commit;
rollback;
set autocommit = 1;
查询内置变量:select @@autocommit;
增加一行数据统计合计:with rollup;
增加后缀:select concat('@qq.com') from 表名;
合并数据:union,union all
索引:主键索引
检测索引是否启用: explain select * from 表名 G
创建或修改视图:create or replace view 视图表名(字段1,字段2,...) as select * from 表名;
创建触发器:create trigger
数据备份:
mysqldump -u root -p [option] mysql_test > F:ceshi.sql
执行该命令引发的错误:
mysqldump: Couldn't execute 'SELECT COLUMN_NAME,JSON_EXTRACT(HISTOGRAM, '$."number-of-buckets-specified"') FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = 'mysql_test' AND TABLE_NAME = 'customers';': Unknown table 'column_statistics' in information_schema (1109)
解决方法:添加(--column-statistics=0)
mysqldump --column-statistics=0 -u root -p mysql_test > F:ceshi.sql
数据恢复:
source pathdb_name.sql
或
mysqldump -u root -p mysql_test < F:db_name.sql
使用SQL语句导入或导出数据:
导出
select * into outfile 'F:\db_name.sql' from customers;
导入
load data infile 'F:\db_name.sql' into table customers_copy;