{"id":10917,"date":"2023-10-10T10:45:39","date_gmt":"2023-10-10T02:45:39","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=10917"},"modified":"2023-10-10T10:45:38","modified_gmt":"2023-10-10T02:45:38","slug":"kundb%e4%bd%bf%e7%94%a8%e6%b8%b8%e6%a0%87%e5%be%aa%e7%8e%af%e8%8e%b7%e5%8f%96%e6%af%8f%e5%bc%a0%e8%a1%a8%e7%9a%84%e6%9d%a1%e6%95%b0","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=10917","title":{"rendered":"kundb\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u83b7\u53d6\u6bcf\u5f20\u8868\u7684\u6761\u6570"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5728kundb\u4e2d\u5982\u4f55\u901a\u8fc7\u5b58\u50a8\u8fc7\u7a0b\u7edf\u8ba1\u6240\u6709\u8868\u7684\u6761\u6570\uff0c\u4ec5\u4f9b\u53c2\u8003\u3002<\/p>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<h4>\u83b7\u53d6\u67d0\u4e2adatabase\u4e0b\u8868\u7684\u6761\u6570<\/h4>\n<pre><code class=\"language-sql\">DROP PROCEDURE IF EXISTS count_rows;\n\nDELIMITER \/\/\nCREATE PROCEDURE count_rows()\nBEGIN\n    DECLARE done INT DEFAULT FALSE;\n    DECLARE v_table_name VARCHAR(255);\n    DECLARE cur CURSOR FOR\n        SELECT table_name FROM information_schema.tables WHERE table_schema = 'test_database';\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE ;\n    DROP TABLE IF EXISTS temp_table;\n    CREATE  TABLE IF NOT EXISTS temp_table (table_name VARCHAR(255), row_count INT );\n    OPEN cur;\n    read_loop: LOOP\n        FETCH cur INTO v_table_name;\n        IF done THEN\n            LEAVE read_loop;\n        END IF;\n        SET @sql = CONCAT('SELECT COUNT(*) INTO @row_count FROM ', v_table_name);\n        PREPARE stmt FROM @sql;\n        EXECUTE stmt;\n        DEALLOCATE PREPARE stmt;\n        INSERT INTO temp_table (table_name, row_count) VALUES (v_table_name, @row_count);\n    END LOOP;\n    CLOSE cur;\n    SELECT * FROM temp_table;\nEND \/\/\nDELIMITER ;\n\nCALL test_database.count_rows_all();<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2023\/10\/image-1696845387480.png\" alt=\"file\" \/><\/p>\n<h4>\u83b7\u53d6\u6240\u6709database\u4e0b\u8868\u7684\u6761\u6570<\/h4>\n<pre><code class=\"language-sql\">DROP PROCEDURE IF EXISTS count_rows_all;\nDELIMITER \/\/\nCREATE PROCEDURE count_rows_all()\nBEGIN\n    DECLARE done INT DEFAULT FALSE;\n    DECLARE v_db_name VARCHAR(255);\n    DECLARE v_table_name VARCHAR(255);\n    DECLARE cur CURSOR FOR\n        SELECT table_schema,table_name FROM information_schema.tables where table_schema not in ('information_schema','performance_schema','mysql','sys');\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE ;\n    DROP TABLE IF EXISTS temp_table;\n    CREATE  TABLE IF NOT EXISTS temp_table (db_name VARCHAR(255),table_name VARCHAR(255), row_count INT );\n    OPEN cur;\n    read_loop: LOOP\n        FETCH cur INTO v_db_name,v_table_name;\n        IF done THEN\n            LEAVE read_loop;\n        END IF;\n        SET @sql = CONCAT('SELECT COUNT(*) INTO @row_count FROM ', v_db_name,'.',v_table_name);\n        PREPARE stmt FROM @sql;\n        EXECUTE stmt;\n        DEALLOCATE PREPARE stmt;\n        INSERT INTO temp_table (db_name,table_name, row_count) VALUES (v_db_name,v_table_name, @row_count);\n    END LOOP;\n    CLOSE cur;\n    SELECT * FROM temp_table;\nEND \/\/\nDELIMITER ;\n\nCALL test_database.count_rows_all();<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/nj.transwarp.cn:8180\/wp-content\/uploads\/2023\/10\/image-1696845502059.png\" alt=\"file\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 \u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5728kundb\u4e2d\u5982\u4f55\u901a\u8fc7\u5b58\u50a8\u8fc7\u7a0b\u7edf\u8ba1\u6240\u6709\u8868\u7684\u6761\u6570\uff0c\u4ec5\u4f9b\u53c2\u8003\u3002 \u8be6\u7ec6\u8bf4\u660e \u83b7\u53d6\u67d0\u4e2adatab ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=10917\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[240],"tags":[],"class_list":["post-10917","post","type-post","status-publish","format-standard","hentry","category-operation"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/10917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10917"}],"version-history":[{"count":2,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/10917\/revisions"}],"predecessor-version":[{"id":10921,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/10917\/revisions\/10921"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}