lock table cxuan005 read;
select * from cxuan005 where id = 111;
select * from cxuan005;
update cxuan005 set info='cxuan' where id = 111;
unlock tables;
select * from cxuan005 where id = 111;
show variables like 'autocommit';
update cxuan005 set info='cxuan' where id = 111;
如果想要关闭数据库的自动提交应该怎么做呢?
set autocommit = 0;
set autocommit = 1;
这里注意一下特殊操作。 在 MySQL 中,存在一些特殊的命令,如果在事务中执行了这些命令,会马上强制执行 commit 提交事务;比如 DDL 语句(create table/drop table/alter/table)、lock tables 语句等等。 不过,常用的 select、insert、update 和 delete命令,都不会强制提交事务。
start transaction;
... # 一条或者多条语句
commit;
start transaction;
select * from cxuan005;
update cxuan005 set info='cxuan';
start transaction; # 开启一个新的事务
insert into cxuan005(id,info) values (555,'cxuan005'); # 插入一条数据
commit and chain; # 提交当前事务并重新开启一个事务
update cxuan005 set info = 'cxuan' where id = 555;
commit;
select * from cxuan005;
start transaction;
delete from cxuan005 where id = 555;
rollback;
这里切忌一点:delete 删除语句一定要加 where ,不加 where 语句的删除就是耍流氓。
start transaction;
insert into cxuan005(id,info) values(666,'cxuan666');
select * from cxuan005 where id = 666;
savepoint test;
insert into cxuan005(id,info) values(777,'cxuan777');
select * from cxuan005 where id = 777;
rollback to savepoint test;
select @@sql_mode;
select id,info from cxuan005;
select id,info from cxuan005 group by info;
select id,info from cxuan005 group by id,info;
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
select id,info from cxuan005 group by info;
当使用 innodb 存储引擎表时,考虑使用 innodb_strict_mode 模式的 sql_mode,它能增量额外的错误检测功能。
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE';
insert into cxuan003 values(111,'study','0000-00-00');
insert into cxuan003 values(111,'study','2021-00-00');
insert into cxuan003 values(111,'study','2021-01-00');
set @@session.sql_mode='xx_mode'
set session sql_mode='xx_mode'
set global sql_mode='xx_mode';
set @@global.sql_mode='xx_mode';
[mysqld]
sql-mode = "xx_mode"
select 'aaaabbbccc' regexp '^a';
同样的,$ 会在末尾处进行匹配,如下所示
select 'aaaabbbccc' regexp 'c$';
. 匹配单个任意字符
select 'berska' regexp '.s', 'zara' regexp '.a';
[...] 表示匹配括号内的任意字符,示例如下
select 'whosyourdaddy' regexp '[abc]';
[^...] 匹配括号内不包含的任意字符,和 [...] 是相反的,如果有任何匹配不上,返回 0 ,全部匹配上返回 1。
select 'x' regexp '[^xyz]';
n* 表示匹配零个或者多个 n 字符串,如下
select 'aabbcc' regexp 'd*';
n+ 表示匹配 1 个或者 n 个字符串
select 'aabbcc' regexp 'd+';
n?
的用法和 n+ 类似,只不过 n? 可以匹配空串
CREATE TABLE `clerk_Info` (
`id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`salary` decimal(10,2) DEFAULT NULL,
`companyId` int(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
select * from clerk_info order by rand();
select name,sum(salary) from clerk_info group by name with rollup;
这里需要注意一点,不能同时使用 ORDER BY 字句对结果进行排序,ROLLUP 和 ORDER BY 是互斥的。
c xu an
拼接成为了一个字符串,另外需要注意一点,任何和 NULL 进行字符串拼接的结果都是 NULL。
NOW(): 返回当前的日期和时间
☞新的一年,这7个“菜鸟坑”千万别再踩了!