From 4aeefcfa7e295e3fa49c0f4f696852c446b9a587 Mon Sep 17 00:00:00 2001 From: AaronXu <718827633@qq.com> Date: Mon, 2 Feb 2026 09:38:20 +0800 Subject: [PATCH] =?UTF-8?q?02-02-=E5=91=A8=E4=B8=80=5F09-38-20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03.数据库/01.Mysql.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/03.数据库/01.Mysql.md b/03.数据库/01.Mysql.md index 68d7b10..1b6343f 100644 --- a/03.数据库/01.Mysql.md +++ b/03.数据库/01.Mysql.md @@ -2153,13 +2153,13 @@ CREATE TABLE talbe_name (id int) ENGINE = ; ```shell [root@db01 ~]# cp -r /application/mysql/data/world/ /data/3307/data/ -[root@db01 ~]# chown -R mysql.mysql /application/mysql/data/world +[root@db01 ~]# chown -R mysql.mysql /data/3307/data/ ``` 2. 启动新数据库 ```shell -#pkill mysqld 先干掉mysql +[root@db01 ~]# pkill mysqld #先干掉mysql [root@db01 ~]# mysqld_safe --defaults-file=/data/3307/my.cnf & ``` @@ -2238,6 +2238,15 @@ mysql> alter table city_new import tablespace; mysql> alter table city_new rename city; ``` +10. 恢复索引和外键 + +```sql +mysql> alter table city add index idx_city(Population,CountryCode); +mysql> alter table city add constraint `city_ibfk_1` foreign key (`CountryCode`) references `country` (`Code`); +``` + +- 恢复剩下的其他表,最后将外键加回来 + # 13. MySQL事务 ## 13.1 事务 @@ -2431,6 +2440,13 @@ transaction_isolation=read-commit > 注 *:SQL 标准中 RR 未解决幻读,**InnoDB 通过 Next-Key Lock 彻底解决幻读**。 +- 脏读 + - A 事务改了数据但**没提交**,B 事务此时读到了 A 的**未提交修改**;后续 A 事务**回滚**,B 事务读到的就是 “不存在的虚假数据”(脏数据)。 +- 不可重复读 + - A 事务中**多次读取同一数据**,在 A 事务未结束时,B 事务**修改并提交**了该数据;导致 A 事务后续再读,结果和第一次不一样。 +- 幻读 + - A 事务中**多次执行同一范围查询**,在 A 事务未结束时,B 事务**插入 / 删除并提交**了符合该范围的新数据;导致 A 事务后续再查,结果的**行数变多 / 变少**,像出现了 “幻觉”。 + # 14. MySQL日志管理 ## 14.1 日志简介