Compare commits
2 Commits
0ce3a0ccdf
...
f544e5f59f
| Author | SHA1 | Date | |
|---|---|---|---|
| f544e5f59f | |||
| fe6f53c187 |
@@ -2,7 +2,14 @@
|
|||||||
show global status like 'Innodb_page_size';
|
show global status like 'Innodb_page_size';
|
||||||
|
|
||||||
# 查询用户
|
# 查询用户
|
||||||
select * from mysql.user;
|
select *
|
||||||
|
from mysql.user;
|
||||||
|
|
||||||
# 查询表的创建语句
|
# 查询表的创建语句
|
||||||
SHOW CREATE TABLE sku.person;
|
show create table sku.person;
|
||||||
|
|
||||||
|
# 查询某个表占用的空间
|
||||||
|
select concat(round(sum(data_length / 1024 / 1024), 2), 'MB') as size
|
||||||
|
from information_schema.tables
|
||||||
|
where table_schema = 'fortern_qqnt'
|
||||||
|
and table_name = 'group_msg_table';
|
||||||
|
|||||||
14
MySQL/transaction-error/ddl.sql
Normal file
14
MySQL/transaction-error/ddl.sql
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
create schema errors;
|
||||||
|
-- 生成演示用的表
|
||||||
|
create table errors.customer
|
||||||
|
(
|
||||||
|
id int auto_increment
|
||||||
|
primary key,
|
||||||
|
username varchar(50) not null
|
||||||
|
);
|
||||||
|
create table errors.customer_back
|
||||||
|
(
|
||||||
|
id int auto_increment
|
||||||
|
primary key,
|
||||||
|
username varchar(50) not null
|
||||||
|
);
|
||||||
42
MySQL/transaction-error/user_a.sql
Normal file
42
MySQL/transaction-error/user_a.sql
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
-- example 1
|
||||||
|
|
||||||
|
-- ========== 0 =========
|
||||||
|
start transaction;
|
||||||
|
-- A先查询
|
||||||
|
select *
|
||||||
|
from customer;
|
||||||
|
-- ========== 1 =========
|
||||||
|
|
||||||
|
-- ========== 2 =========
|
||||||
|
-- 在 B 添加数据后,A 尝试进行修改。奇怪的是,明明查询不到,居然可以修改成功
|
||||||
|
update customer
|
||||||
|
set username = 'wuhu'
|
||||||
|
where id = 1;
|
||||||
|
-- A 再次查询表中数据,发现修改的那一行现身了
|
||||||
|
select *
|
||||||
|
from customer;
|
||||||
|
commit;
|
||||||
|
-- ========== 3 =========
|
||||||
|
|
||||||
|
|
||||||
|
-- example 2
|
||||||
|
-- ========== 0 =========
|
||||||
|
start transaction;
|
||||||
|
-- A先查询,查到数据如下:
|
||||||
|
-- 1,Fortern
|
||||||
|
-- 2,Maxin
|
||||||
|
-- 3,MooGeo
|
||||||
|
select *
|
||||||
|
from customer;
|
||||||
|
-- ========== 1 =========
|
||||||
|
|
||||||
|
-- ========== 2 =========
|
||||||
|
-- A 备份表中数据到另一个表
|
||||||
|
insert into customer_back select * from customer;
|
||||||
|
commit;
|
||||||
|
-- 结果备份表中的数据居然是被其他事物修改的数据!!
|
||||||
|
select * from customer_back;
|
||||||
|
-- 为什么会这样?
|
||||||
|
-- ========== 3 =========
|
||||||
|
|
||||||
|
select * from customer where id = 1;
|
||||||
20
MySQL/transaction-error/user_b.sql
Normal file
20
MySQL/transaction-error/user_b.sql
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
-- example 1
|
||||||
|
|
||||||
|
-- ========== 1 =========
|
||||||
|
start transaction;
|
||||||
|
-- B插入数据
|
||||||
|
insert into customer (id, username)
|
||||||
|
values (1, 'Fortern'),
|
||||||
|
(2, 'Maxin'),
|
||||||
|
(3, 'MooGeo');
|
||||||
|
commit;
|
||||||
|
-- ========== 2 =========
|
||||||
|
|
||||||
|
|
||||||
|
-- example 2
|
||||||
|
-- ========== 1 =========
|
||||||
|
start transaction;
|
||||||
|
-- B 修改所有人的name
|
||||||
|
update customer set username = '哈基米' where true;
|
||||||
|
commit;
|
||||||
|
-- ========== 2 =========
|
||||||
Reference in New Issue
Block a user