日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

doesnt exist table_MYSQL ERROR 1146 Table doesnt exist 解析

發布時間:2025/4/5 数据库 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 doesnt exist table_MYSQL ERROR 1146 Table doesnt exist 解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原創轉載請注明出處

源碼版本 5.7.14

在MYSQL使用innodb的時候我們有時候會看到如下報錯:

ERROR 1146 (42S02): Table 'test.test1bak' doesn't exist

首先總結下原因:

缺少frm文件

innodb數據字典不包含這個表

我們重點討論情況2,因為情況1是顯而易見的。

在使用innodb存儲引擎的時候某些時候我們show tables能夠看到這個表,但是如果進行任何操作會報錯如下:

mysql> show tables;

| test1bak |

mysql> desc test1bak ;

ERROR 1146 (42S02): Table 'test.test1bak' doesn't exist

也許你會說我明明能夠看到這個表啊,為什么訪問還會報錯呢?其實要清楚innodb有自己的數據字典,只要有frm 文件存在show tables就能看到,但是最終是否能夠正常打開表結構在innodb中還依賴于innodb的數據字典,主要的包含:

INNODB_SYS_columns

INNODB_SYS_FIELDS

INNODB_SYS_TABLES

INNODB_SYS_INDEXES

如果報錯出現我們需要首先查看的是INNODB_SYS_TABLES是否包含了這個表的信息。也許在這些數據字典中也許某些列并顯示并不是那么明確,比如

mysql> select * from information_schema.innodb_sys_tables where name='test/kkkkm1';

+----------+-------------+------+--------+-------+-------------+------------+---------------+------------+

| TABLE_ID | NAME | FLAG | N_COLS | SPACE | FILE_FORMAT | ROW_FORMAT | ZIP_PAGE_SIZE | SPACE_TYPE |

+----------+-------------+------+--------+-------+-------------+------------+---------------+------------+

| 374 | test/kkkkm1 | 33 | 6 | 540 | Barracuda | Dynamic | 0 | Single |

+----------+-------------+------+--------+-------+-------------+------------+---------------+------------+

比如這里的FLAG列為33,他實際上是一個位圖表示方式,分別表示如下信息:

/* Table and tablespace flags are generally not used for the Antelope file

format except for the low order bit, which is used differently depending on

where the flags are stored.

==================== Low order flags bit =========================

| REDUNDANT | COMPACT | COMPRESSED and DYNAMIC

SYS_TABLES.TYPE | 1 | 1 | 1

dict_table_t::flags | 0 | 1 | 1

FSP_SPACE_FLAGS | 0 | 0 | 1

fil_space_t::flags | 0 | 0 | 1

/** Width of the COMPACT flag */

#define DICT_TF_WIDTH_COMPACT 1

/** Width of the ZIP_SSIZE flag */

#define DICT_TF_WIDTH_ZIP_SSIZE 4

/** Width of the ATOMIC_BLOBS flag. The Antelope file formats broke up

BLOB and TEXT fields, storing the first 768 bytes in the clustered index.

Barracuda row formats store the whole blob or text field off-page atomically.

Secondary indexes are created from this external data using row_ext_t

to cache the BLOB prefixes. */

#define DICT_TF_WIDTH_ATOMIC_BLOBS 1

/** If a table is created with the MYSQL option DATA DIRECTORY and

innodb-file-per-table, an older engine will not be able to find that table.

This flag prevents older engines from attempting to open the table and

allows InnoDB to update_create_info() accordingly. */

#define DICT_TF_WIDTH_DATA_DIR 1

/** Width of the SHARED tablespace flag.

It is used to identify tables that exist inside a shared general tablespace.

If a table is created with the TABLESPACE=tsname option, an older engine will

not be able to find that table. This flag prevents older engines from attempting

to open the table and allows InnoDB to quickly find the tablespace. */

#define DICT_TF_WIDTH_SHARED_SPACE 1

接下來我們分析一下為什么是FLAG是33如下:

33的二進制為00100001從低位開始

1:從源碼注釋來看本位COMPACT/COMPRESSED/DYNAMIC均為1

0000: ZIP_SSIZE flag 這四位用于支持壓縮功能如COMPRESSED

1:ATOMIC_BLOBS flag 這一位是COMPACT和DYNAMIC主要區別所在,請看源碼注釋

0:DATA DIRECTORY and innodb-file-per-table flag為了支持DATA DIRECTORY語法

0:SHARED tablespace flag為了支持TABLESPACE語法

然后我們測試一下:

如果我們建立如下的表:

CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE = innodb_file_per_table

DATA DIRECTORY = '/root/mysql5.7.14/percona-server-5.7.14-7/mysql-test/var/mysqld.1';

其type為97二進制為 01100001:使用DATA DIRECTORY建立使用ATOMIC_BLOBS且無壓縮則DYNAMIC格式

詳見:15.5.5 Creating a File-Per-Table Tablespace Outside the Data Directory

如果我們建立如下的表:

CREATE TABLESPACE tt1 ADD DATAFILE '/root/mysql5.7.14/tt1.ibd';

CREATE TABLE tsh (c1 INT ) TABLESPACE tt1 ROW_FORMAT=COMPACT ;

其type為129二進制為 10000001:使用TABLESPACE語法建立不使用ATOMIC_BLOBS且無壓縮則為COMPACT格式

詳見:15.5.9 InnoDB General Tablespaces

我們可以看到使用8位一個字節而已就可以表示出大量的信息,這也是位圖的優勢,其他比如 MTYPE/PRTYPE也是這種表示方式

接下來我們回到主題,需要看看這個錯到底是哪里報錯來的?進行trace后如下,我們來看看主要部分:

注意這里的trace是mysql debug版本下查看函數調用的主要方法參考官方文檔26.5.1.2 Creating Trace Files

502 T@2: | | | | | | | | | | | >ha_innobase::open_dict_table

503 T@2: | | | | | | | | | | | | >dict_table_open_on_name

504 T@2: | | | | | | | | | | | | | dict_table_open_on_name: table: 'test/test1bak'

505 T@2: | | | | | | | | | | | | | >dict_table_check_if_in_cache_low

506 T@2: | | | | | | | | | | | | | | dict_table_check_if_in_cache_low: table: 'test/test1bak'

507 T@2: | | | | | | | | | | | | |

508 T@2: | | | | | | | | | | | | | >dict_load_table

509 T@2: | | | | | | | | | | | | | | dict_load_table: loading table: 'test/test1bak'

510 T@2: | | | | | | | | | | | | | | >dict_table_check_if_in_cache_low

511 T@2: | | | | | | | | | | | | | | | dict_table_check_if_in_cache_low: table: 'test/test1bak'

512 T@2: | | | | | | | | | | | | | |

513 T@2: | | | | | | | | | | | | | | >dict_load_table_one

514 T@2: | | | | | | | | | | | | | | | dict_load_table_one: table: test/test1bak

515 T@2: | | | | | | | | | | | | | | | >dict_table_check_if_in_cache_low

516 T@2: | | | | | | | | | | | | | | | | dict_table_check_if_in_cache_low: table: 'SYS_TABLES'

517 T@2: | | | | | | | | | | | | | | |

518 T@2: | | | | | | | | | | | | | | | >btr_cur_search_to_nth_level

519 T@2: | | | | | | | | | | | | | | |

520 T@2: | | | | | | | | | | | | | |

521 T@2: | | | | | | | | | | | | |

522 T@2: | | | | | | | | | | | |

523 T@2: | | | | | | | | | | | <:open_dict_table>

524 T@2: | | | | | | | | | | | >sql_print_warning

525 T@2: | | | | | | | | | | | | >error_log_print

526 T@2: | | | | | | | | | | | | | >print_buffer_to_file

527 T@2: | | | | | | | | | | | | | | enter: buffer: InnoDB: Cannot open table test/test1bak from the internal data dictionary of InnoDB though the .frm file for the

table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.

528 T@2: | | | | | | | | | | | | |

529 T@2: | | | | | | | | | | | |

530 T@2: | | | | | | | | | | |

其實大概步驟就是

Checks if a table is in the dictionary cache

根據dict_sys->table_hash尋找

Loads a table definition and also all its index definitions.

通過掃描字典的B+樹進行加載

如果不能找到則報錯

這樣也就解釋了為什么show tables能夠看到但是select卻報錯Table doesn't exist ,而從原理上講show tables只是查看了frm文件。

另外這里也提一個案列,曾經有一個朋友問我他將整個庫目錄都拷貝了,但是表能看到但是一操作就報Table doesn't exist,顯然他沒有拷貝ibdata1,數據字典的引導信息都存在這里面文件的第7個page中,其b+樹也是存在其中,用源碼解釋一下:

/**********************************************************************//**

Gets a pointer to the dictionary header and x-latches its page.

@return pointer to the dictionary header, page x-latched */

dict_hdr_t*

dict_hdr_get(

/*=========*/

mtr_t* mtr) /*!< in: mtr */

{

buf_block_t* block;

dict_hdr_t* header;

block = buf_page_get(page_id_t(DICT_HDR_SPACE, DICT_HDR_PAGE_NO),

univ_page_size, RW_X_LATCH, mtr);

header = DICT_HDR + buf_block_get_frame(block);

buf_block_dbg_add_level(block, SYNC_DICT_HEADER);

return(header);

}

注意這里的 DICT_HDR_SPACE, DICT_HDR_PAGE_NO分別是宏定義

/* Space id and page no where the dictionary header resides */

#define DICT_HDR_SPACE 0 /* the SYSTEM tablespace */

#define DICT_HDR_PAGE_NO FSP_DICT_HDR_PAGE_NO

#define FSP_DICT_HDR_PAGE_NO 7 /*!< data dictionary header

page, in tablespace 0 */

space 0就是ibdata1的space_no,7當然就是引導塊,這哥們連ibdata1都沒拷貝,當然innodb數據字典自然不包含這些表了。其實也是上面描述的原理 。

那么正確的拷貝的方式一定是停機后,整個數據目錄進行拷貝,而不是僅僅拷貝需要的庫的目錄,否則innodb數據字典是不能正常加載的。

最后附帶space 0的部分塊解釋

/*--------------------------------------*/

#define FSP_XDES_OFFSET 0 /* !< extent descriptor */

#define FSP_IBUF_BITMAP_OFFSET 1 /* !< insert buffer bitmap */

/* The ibuf bitmap pages are the ones whose

page number is the number above plus a

multiple of XDES_DESCRIBED_PER_PAGE */

#define FSP_FIRST_INODE_PAGE_NO 2 /*!< in every tablespace */

/* The following pages exist

in the system tablespace (space 0). */

#define FSP_IBUF_HEADER_PAGE_NO 3 /*!< insert buffer

header page, in

tablespace 0 */

#define FSP_IBUF_TREE_ROOT_PAGE_NO 4 /*!< insert buffer

B-tree root page in

tablespace 0 */

/* The ibuf tree root page number in

tablespace 0; its fseg inode is on the page

number FSP_FIRST_INODE_PAGE_NO */

#define FSP_TRX_SYS_PAGE_NO 5 /*!< transaction

system header, in

tablespace 0 */

#define FSP_FIRST_RSEG_PAGE_NO 6 /*!< first rollback segment

page, in tablespace 0 */

#define FSP_DICT_HDR_PAGE_NO 7 /*!< data dictionary header

page, in tablespace 0 */

****/*--------------------------------------*/****

總結

以上是生活随笔為你收集整理的doesnt exist table_MYSQL ERROR 1146 Table doesnt exist 解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久草视频这里只有精品 | 成人小视频在线看 | 亚洲一级Av无码毛片久久精品 | 日大逼| 久久精品一本 | 久久久久高清 | www.av在线 | 天天操夜夜干 | 麻豆精品国产精华精华液好用吗 | 深夜福利1000| 国产伦精品一区二区三区视频免费 | 一区二区视频在线 | 97久久人澡人人添人人爽 | 精品乱子伦一区二区 | 亚洲夜夜爽| 黄色av播放 | 亚洲综合福利 | 亚洲高清视频免费观看 | 亚洲大胆| 亚洲日本japanese丝袜 | 四虎成人在线观看 | 少妇精品久久久一区二区三区 | 日韩av网站在线 | 日韩av不卡在线 | 日韩成人在线看 | 青青操影院 | 天天干天天爽天天操 | www亚洲视频 | 欧美乱欲视频 | 日韩精品一区在线观看 | 亚洲制服丝袜在线播放 | 久久夜色精品亚洲 | 校霸被c到爽夹震蛋上课高潮 | 欧美日国产 | 亚洲成人18| 91免费视频网 | 国产福利91 | 99re久久精品国产 | 啪啪激情网 | 不卡的一区二区 | 91国模少妇一区二区三区 | 成年人免费在线观看视频网站 | 国产精品99无码一区二区视频 | 99热这里精品 | 亚洲视频456 | 乱熟女高潮一区二区在线 | 国产精品久久AV无码 | 蓝牛av| 图片区偷拍区小说区 | 超碰91在线 | 成人午夜视频在线免费观看 | 亚洲精品乱码久久久久久久久久久久 | 日韩精彩视频 | 伊人春色网站 | 中国男女全黄大片 | 少妇太紧太爽又黄又硬又爽 | 成年人免费毛片 | 啪啪视屏| 欧美日韩免费高清 | 国产午夜在线观看 | 青青草国产精品视频 | 国产精品欧美激情在线 | 成年性生交大片免费看 | 天天摸天天操天天爽 | 97在线免费公开视频 | 日韩av一区二区三区在线观看 | 亚洲宗人网| 日本东京热一区二区 | 激情 亚洲| 色五丁香 | 亚洲中文一区二区 | 久久福利小视频 | 日本少妇与黑人 | 催眠美妇肉奴系统 | 超级黄色片| 黄a毛片 | 麻豆av一区二区三区久久 | 中文亚洲字幕 | 日韩av片在线看 | 欧美日韩国产精品成人 | 污污视频免费看 | 欧美情趣视频 | 精久久久 | 色婷婷综合久久 | 国产精品电影网站 | 视频一区二区三区在线观看 | 国产免费又爽又色又粗视频 | 人操人人 | 国产精品日日摸天天碰 | 久久国产精品久久久久久 | 亚洲成年人网站在线观看 | 成人依依| 怡红院亚洲 | 女女同性女同一区二区三区九色 | 日本成人在线免费视频 | 欧美国产精品一区 | 99热免费在线 | 无码 制服 丝袜 国产 另类 | 裸体裸乳被免费看视频 |