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

歡迎訪問 生活随笔!

生活随笔

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

数据库

mysql常用快速查询修改操作

發布時間:2023/12/9 数据库 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql常用快速查询修改操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mysql常用快速查詢修改操作

一、查找并修改非innodb引擎為innodb引擎

# 通用操作 mysql> select concat('alter table ',table_schema,'.',table_name,' engine=innodb;') from information_schema.tables where table_schema not in ('information_schema','mysql','performance_schema') and engine='myisam';

?


# 示例
select
concat('alter table test.',table_name,' engine=innodb;') from information_schema.tables where table_schema not in ('information_schema','mysql','performance_schema') and engine='myisam';
mysql> select concat('alter table test.',table_name,' engine=innodb;') from information_schema.tables where table_schema not in ('information_schema','mysql','performance_schema') and engine='myisam';
+----------------------------------------------------------+
| concat('alter table test.',table_name,' engine=innodb;') |
+----------------------------------------------------------+
| alter table test.tempusermap engine=innodb;????????????? |
| alter table test.users_relation_list engine=innodb;????? |
+----------------------------------------------------------+
2 rows in set (0.58 sec)

mysql>

二、查詢數據大小

在需要備份數據庫里面的數據時,我們需要知道數據庫占用了多少磁盤大小,可以通過一些sql語句查詢到整個數據庫的容量,也可以單獨查看表所占容量。

1、要查詢表所占的容量,就是把表的數據和索引加起來就可以了

mysql> select TABLE_SCHEMA,(sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1024/1024/1024 AS 'size_g' from information_schema.tables where TABLE_SCHEMA NOT IN ('information_schema','mysql','performance_schema') group by TABLE_SCHEMA; +--------------+-----------------+ | TABLE_SCHEMA | size_g | +--------------+-----------------+ | db01 | 13.810716629028 | | db02 | 0.279693603516 | | test | 0.143768310547 | +--------------+-----------------+ 3 rows in set (9.06 sec)

2、查詢所有的數據大小

select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables; -- 查詢所有的數據大小 mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables; -- 查詢所有的數據大小 +-------------------------------------------------+ | concat(round(sum(DATA_LENGTH/1024/1024),2),'M') | +-------------------------------------------------+ | 5324.54M | +-------------------------------------------------+ 1 row in set (8.60 sec)

3、查詢某個表的數據

select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from tables where table_schema='test' AND table_name='USER';mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables where table_schema='test' AND table_name='USER'; +-------------------------------------------------+ | concat(round(sum(DATA_LENGTH/1024/1024),2),'M') | +-------------------------------------------------+ | 73.61M | +-------------------------------------------------+ 1 row in set (0.03 sec)

mysql>select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),'M') AS 'SIZE_MB' from information_schema.tables where table_schema='db222' group by table_name order by SIZE_MB asc,table_name asc;
+----------------+---------+
| table_name???? | SIZE_MB |
+----------------+---------+
| t1???????????? | 0.02M?? |
| t_user_partion | 487.33M |
| t_user_id3???? | 71.61M? |
| t_user_id0???? | 74.61M? |
| t_user_id1???? | 74.61M? |
| t_user_id2???? | 74.61M? |
| t_user_id4???? | 74.61M? |
| t_user_id5???? | 74.61M? |
| t_user_id6???? | 74.61M? |
| t_user_id7???? | 74.61M? |
| t_user_id8???? | 74.61M? |
| t_user_id9???? | 74.61M? |
+----------------+---------+
12 rows in set (0.00 sec)

mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') AS table_size,table_name from information_schema.tables where table_schema='fudao_account' AND table_name IN ('db3','db2','db3','db1') group by table_name;
+------------+------------------------+
| table_size | table_name???????????? |
+------------+------------------------+
| 2.52M????? | db1?????????? ??? ??? ?? |
| 0.23M????? | db2??????????????????? |
| 0.30M????? | db3??????????????????? |
+------------+------------------------+
3 rows in set (0.00 sec)

mysql>

?



轉載于:https://www.cnblogs.com/bjx2020/p/9103680.html

總結

以上是生活随笔為你收集整理的mysql常用快速查询修改操作的全部內容,希望文章能夠幫你解決所遇到的問題。

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