码迷,mamicode.com
首页 > 数据库 > 详细

SQL简单实用的优化方法

时间:2016-04-29 20:16:50      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:sql简单实用的优化方法

分析表:MyISAM、InnoDB、BDB

mysql> analyze table payment; #MyISAM 使用myisamchk -a

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

| Table          | Op      | Msg_type | Msg_text |

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

| sakila.payment | analyze | status   | OK       |

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

1 row in set (0.10 sec)


mysql> 

mysql> check table payment_myisam ; #MyISAM、InnoDB #也可以检查视图

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

| Table                 | Op    | Msg_type | Msg_text |

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

| sakila.payment_myisam | check | status   | OK       |

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

1 row in set (0.00 sec)


mysql> 

优化表:MyISAM、InnoDB、BDB

mysql> optimize table  payment_myisam ;

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

| Table                 | Op       | Msg_type | Msg_text |

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

| sakila.payment_myisam | optimize | status   | OK       |

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

1 row in set (0.01 sec)


mysql> 

使用独立表空间:

mysql> show variables like "innodb_file_per_table";

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

| Variable_name         | Value |

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

| innodb_file_per_table | ON    |

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

1 row in set (0.00 sec)


mysql> set GLOBAL innodb_file_per_table = on;      

Query OK, 0 rows affected (0.00 sec)


mysql>


删除大量数据后InnoDB表可以通过alter table:

mysql> alter table payment engine=innodb;

Query OK, 0 rows affected (4.63 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> 


关于字符集的设置:

character_set_server=utf8mb4

default_character-set=utf8mb4


SQL简单实用的优化方法

标签:sql简单实用的优化方法

原文地址:http://wangqh.blog.51cto.com/5367393/1769015

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!