mysql优化之sakila测试数据库

下载地址,选择相应的版本来进行安装测试

http://dev.mysql.com/doc/index-other.html

相关说明

http://dev.mysql.com/doc/sakila/en/sakila-installation.html

outous-MacBook-Pro:~ wangtao$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.6.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 5.6.20    |
+-----------+
1 row in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| apphomebiz         |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.01 sec)

mysql> source /Users/wangtao/Downloads/sakila-db/sakila-schema.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+----------------------------+
| Tables_in_sakila           |
+----------------------------+
| actor                      |
| actor_info                 |
| address                    |
| category                   |
| city                       |
| country                    |
| customer                   |
| customer_list              |
| film                       |
| film_actor                 |
| film_category              |
| film_list                  |
| film_text                  |
| inventory                  |
| language                   |
| nicer_but_slower_film_list |
| payment                    |
| rental                     |
| sales_by_film_category     |
| sales_by_store             |
| staff                      |
| staff_list                 |
| store                      |
+----------------------------+
23 rows in set (0.00 sec)

mysql> source /Users/wangtao/Downloads/sakila-db/sakila-data.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Database changed
Query OK, 0 rows affected (0.00 sec)

Query OK, 200 rows affected (0.00 sec)
Records: 200  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 603 rows affected (0.00 sec)
Records: 603  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 16 rows affected (0.00 sec)
Records: 16  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 600 rows affected (0.00 sec)
Records: 600  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 109 rows affected (0.00 sec)
Records: 109  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 599 rows affected (0.02 sec)
Records: 599  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 1000 rows affected (0.13 sec)
Records: 1000  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 5462 rows affected (0.04 sec)
Records: 5462  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 1000 rows affected (0.01 sec)
Records: 1000  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 4581 rows affected (0.04 sec)
Records: 4581  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 6 rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 14885 rows affected (0.24 sec)
Records: 14885  Duplicates: 0  Warnings: 0

Query OK, 1164 rows affected (0.01 sec)
Records: 1164  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 12377 rows affected (0.21 sec)
Records: 12377  Duplicates: 0  Warnings: 0

Query OK, 3667 rows affected (0.05 sec)
Records: 3667  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> use sakila;
Database changed
mysql> show tables;
+----------------------------+
| Tables_in_sakila           |
+----------------------------+
| actor                      |
| actor_info                 |
| address                    |
| category                   |
| city                       |
| country                    |
| customer                   |
| customer_list              |
| film                       |
| film_actor                 |
| film_category              |
| film_list                  |
| film_text                  |
| inventory                  |
| language                   |
| nicer_but_slower_film_list |
| payment                    |
| rental                     |
| sales_by_film_category     |
| sales_by_store             |
| staff                      |
| staff_list                 |
| store                      |
+----------------------------+
23 rows in set (0.00 sec)

mysql> select * from store;
+----------+------------------+------------+---------------------+
| store_id | manager_staff_id | address_id | last_update         |
+----------+------------------+------------+---------------------+
|        1 |                1 |          1 | 2006-02-15 04:57:12 |
|        2 |                2 |          2 | 2006-02-15 04:57:12 |
+----------+------------------+------------+---------------------+
2 rows in set (0.00 sec)

mysql> select count(*) from film;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.00 sec)

mysql> select count(*) from film_text;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.00 sec)

mysql> show variables like ‘slow_query_log‘;
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| slow_query_log | OFF   |
+----------------+-------+
1 row in set (0.01 sec)

mysql> show variables like ‘%log%‘;
+-----------------------------------------+----------------------------------------------------+
| Variable_name                           | Value                                              |
+-----------------------------------------+----------------------------------------------------+
| back_log                                | 80                                                 |
| binlog_cache_size                       | 32768                                              |
| binlog_checksum                         | CRC32                                              |
| binlog_direct_non_transactional_updates | OFF                                                |
| binlog_format                           | STATEMENT                                          |
| binlog_max_flush_queue_time             | 0                                                  |
| binlog_order_commits                    | ON                                                 |
| binlog_row_image                        | FULL                                               |
| binlog_rows_query_log_events            | OFF                                                |
| binlog_stmt_cache_size                  | 32768                                              |
| binlogging_impossible_mode              | IGNORE_ERROR                                       |
| expire_logs_days                        | 0                                                  |
| general_log                             | OFF                                                |
| general_log_file                        | /usr/local/mysql/data/outous-MacBook-Pro.log       |
| innodb_api_enable_binlog                | OFF                                                |
| innodb_flush_log_at_timeout             | 1                                                  |
| innodb_flush_log_at_trx_commit          | 1                                                  |
| innodb_locks_unsafe_for_binlog          | OFF                                                |
| innodb_log_buffer_size                  | 8388608                                            |
| innodb_log_compressed_pages             | ON                                                 |
| innodb_log_file_size                    | 50331648                                           |
| innodb_log_files_in_group               | 2                                                  |
| innodb_log_group_home_dir               | ./                                                 |
| innodb_mirrored_log_groups              | 1                                                  |
| innodb_online_alter_log_max_size        | 134217728                                          |
| innodb_undo_logs                        | 128                                                |
| log_bin                                 | OFF                                                |
| log_bin_basename                        |                                                    |
| log_bin_index                           |                                                    |
| log_bin_trust_function_creators         | OFF                                                |
| log_bin_use_v1_row_events               | OFF                                                |
| log_error                               | /usr/local/mysql/data/outous-MacBook-Pro.local.err |
| log_output                              | FILE                                               |
| log_queries_not_using_indexes           | OFF                                                |
| log_slave_updates                       | OFF                                                |
| log_slow_admin_statements               | OFF                                                |
| log_slow_slave_statements               | OFF                                                |
| log_throttle_queries_not_using_indexes  | 0                                                  |
| log_warnings                            | 1                                                  |
| max_binlog_cache_size                   | 18446744073709547520                               |
| max_binlog_size                         | 1073741824                                         |
| max_binlog_stmt_cache_size              | 18446744073709547520                               |
| max_relay_log_size                      | 0                                                  |
| relay_log                               |                                                    |
| relay_log_basename                      |                                                    |
| relay_log_index                         |                                                    |
| relay_log_info_file                     | relay-log.info                                     |
| relay_log_info_repository               | FILE                                               |
| relay_log_purge                         | ON                                                 |
| relay_log_recovery                      | OFF                                                |
| relay_log_space_limit                   | 0                                                  |
| slow_query_log                          | OFF                                                |
| slow_query_log_file                     | /usr/local/mysql/data/outous-MacBook-Pro-slow.log  |
| sql_log_bin                             | ON                                                 |
| sql_log_off                             | OFF                                                |
| sync_binlog                             | 0                                                  |
| sync_relay_log                          | 10000                                              |
| sync_relay_log_info                     | 10000                                              |
+-----------------------------------------+----------------------------------------------------+
58 rows in set (0.00 sec)

mysql> set global log_queries_not_using_indexes=on;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like ‘%log%‘;
+-----------------------------------------+----------------------------------------------------+
| Variable_name                           | Value                                              |
+-----------------------------------------+----------------------------------------------------+
| back_log                                | 80                                                 |
| binlog_cache_size                       | 32768                                              |
| binlog_checksum                         | CRC32                                              |
| binlog_direct_non_transactional_updates | OFF                                                |
| binlog_format                           | STATEMENT                                          |
| binlog_max_flush_queue_time             | 0                                                  |
| binlog_order_commits                    | ON                                                 |
| binlog_row_image                        | FULL                                               |
| binlog_rows_query_log_events            | OFF                                                |
| binlog_stmt_cache_size                  | 32768                                              |
| binlogging_impossible_mode              | IGNORE_ERROR                                       |
| expire_logs_days                        | 0                                                  |
| general_log                             | OFF                                                |
| general_log_file                        | /usr/local/mysql/data/outous-MacBook-Pro.log       |
| innodb_api_enable_binlog                | OFF                                                |
| innodb_flush_log_at_timeout             | 1                                                  |
| innodb_flush_log_at_trx_commit          | 1                                                  |
| innodb_locks_unsafe_for_binlog          | OFF                                                |
| innodb_log_buffer_size                  | 8388608                                            |
| innodb_log_compressed_pages             | ON                                                 |
| innodb_log_file_size                    | 50331648                                           |
| innodb_log_files_in_group               | 2                                                  |
| innodb_log_group_home_dir               | ./                                                 |
| innodb_mirrored_log_groups              | 1                                                  |
| innodb_online_alter_log_max_size        | 134217728                                          |
| innodb_undo_logs                        | 128                                                |
| log_bin                                 | OFF                                                |
| log_bin_basename                        |                                                    |
| log_bin_index                           |                                                    |
| log_bin_trust_function_creators         | OFF                                                |
| log_bin_use_v1_row_events               | OFF                                                |
| log_error                               | /usr/local/mysql/data/outous-MacBook-Pro.local.err |
| log_output                              | FILE                                               |
| log_queries_not_using_indexes           | ON                                                 |
| log_slave_updates                       | OFF                                                |
| log_slow_admin_statements               | OFF                                                |
| log_slow_slave_statements               | OFF                                                |
| log_throttle_queries_not_using_indexes  | 0                                                  |
| log_warnings                            | 1                                                  |
| max_binlog_cache_size                   | 18446744073709547520                               |
| max_binlog_size                         | 1073741824                                         |
| max_binlog_stmt_cache_size              | 18446744073709547520                               |
| max_relay_log_size                      | 0                                                  |
| relay_log                               |                                                    |
| relay_log_basename                      |                                                    |
| relay_log_index                         |                                                    |
| relay_log_info_file                     | relay-log.info                                     |
| relay_log_info_repository               | FILE                                               |
| relay_log_purge                         | ON                                                 |
| relay_log_recovery                      | OFF                                                |
| relay_log_space_limit                   | 0                                                  |
| slow_query_log                          | OFF                                                |
| slow_query_log_file                     | /usr/local/mysql/data/outous-MacBook-Pro-slow.log  |
| sql_log_bin                             | ON                                                 |
| sql_log_off                             | OFF                                                |
| sync_binlog                             | 0                                                  |
| sync_relay_log                          | 10000                                              |
| sync_relay_log_info                     | 10000                                              |
+-----------------------------------------+----------------------------------------------------+
58 rows in set (0.00 sec)
#生产环境中,这个时间设置的过短的话,短时间内会产生大量的日志文件,可能造成磁盘写满
mysql> show variables like ‘long_query_time‘;
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)

mysql> set global slow_query_log=on;
Query OK, 0 rows affected (0.01 sec)

mysql> use sakila;
Database changed
mysql> select * from store limit 10;
+----------+------------------+------------+---------------------+
| store_id | manager_staff_id | address_id | last_update         |
+----------+------------------+------------+---------------------+
|        1 |                1 |          1 | 2006-02-15 04:57:12 |
|        2 |                2 |          2 | 2006-02-15 04:57:12 |
+----------+------------------+------------+---------------------+
2 rows in set (0.01 sec)

mysql> show variables linke "slow%";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘linke "slow%"‘ at line 1
mysql> show variables like "slow%";
+---------------------+---------------------------------------------------+
| Variable_name       | Value                                             |
+---------------------+---------------------------------------------------+
| slow_launch_time    | 2                                                 |
| slow_query_log      | ON                                                |
| slow_query_log_file | /usr/local/mysql/data/outous-MacBook-Pro-slow.log |
+---------------------+---------------------------------------------------+
3 rows in set (0.00 sec)

mysql> 

查看保存的日志

 /usr/local/mysql/data/outous-MacBook-Pro-slow.log 
outous-MacBook-Pro:~ wangtao$ sudo cat  /usr/local/mysql/data/outous-MacBook-Pro-slow.log
Password:
/usr/local/mysql/bin/mysqld, Version: 5.6.20 (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
# Time: 141217 22:41:51#执行sql的主机信息
# User@Host: root[root] @ localhost []  Id:    16#sql的执行信息,扫描的行数,发送的行数
# Query_time: 0.000181  Lock_time: 0.000072 Rows_sent: 2  Rows_examined: 2
use sakila;

#sql执行时间,时间戳格式

SET timestamp=1418827311;#sql内容
select * from store limit 10;
outous-MacBook-Pro:~ wangtao$ 
时间: 2024-09-30 15:51:04

mysql优化之sakila测试数据库的相关文章

MySQL官方提供的测试数据库下载地址

实际上MySQL也提供了一个测试用的数据库,叫做employees. 直接贴免积分的下载地址: http://download.csdn.net/detail/willswoo/7117031 方法: tar xf employees_db-full-1.0.6.tar.bz2 cd employees_db mysql -uroot -pxxxx < employees.sql即可完成导入(导入后差不多230MB)

mysql优化方向

随着数据的积累,慢慢的我们一些不好的习惯都会在系统中暴露出来,程序执行的效率低,用户体验下降,如果我们不采取一些措施,那么用户就回流失.提高程序的执行效率可能需要做很多工作,但其中一个重要的工作就是mysql优化,或者称为数据库优化. 优化方向 1.表设计合理化(数据库范式)2.添加适当的索引(主键索引.唯一索引.普通索引.全文索引)3.高效的sql(sql语句优化,尤其是慢查询)4.分表技术(水平分割.垂直分割)5.读写分离6.存储过程(预编译的sql语句,提高了执行效率)7.配置优化 例如

MySQL Sakila样本数据库

Sakila样本数据库介绍 Sakila样本数据库是MySQL官方提供的一个模拟DVD租赁信息管理的数据库,提供了一个标准模式,可作为书中例子,教程.文章.样品,等等,对学习测试来说是个不错的选择. 1.下载地址: MySQL :: Other MySQL Documentation https://dev.mysql.com/doc/index-other.html (Example Databases --> sakila database --> zip包或.tar.gz包均可) 2.导

mysql优化-数据库优化、SQL优化

我有一张表w1000,里面有1000万条数据,这张表结构如下:CREATE TABLE `w1000` ( `id` varchar(36) NOT NULL, `name` varchar(10) DEFAULT NULL, `age` int(3) DEFAULT NULL, `money` double(8,2) DEFAULT NULL, `address` varchar(100) DEFAULT NULL, `create_date` datetime(3) DEFAULT NULL

数据库 mysql 优化器原理

MySQL查询优化器有几个目标,但是其中最主要的目标是尽可能地使用索引,并且使用最严格的索引来消除尽可能多的数据行. 你的最终目标是提交SELECT语句查找数据行,而不是排除数据行.优化器试图排除数据行的原因在于它排除数据行的速度越快,那么找到与条件匹配的数据行也就越快. 如何 更好的 利用索引: 1:尽量比较数据类型相同的数据列.当你在比较操作中使用索引数据列的时候,请使用数据类型相同的列.相同的数据类型比不同类型的性能要高一些. 例如,INT与BIGINT是不同的.CHAR(10)被认为是C

MYSQL学习笔记——数据库范式及MYSQL优化整体思路

一.数据库范式                                                                               为了建立冗余较小.结构合理的数据库,设计数据库时必须遵循一定的规则.在关系型数据库中这种规则就称为范式.范式是符合某一种设计要求的总结.要想设计一个结构合理的关系型数据库,必须满足一定的范式. 1.1.第一范式(1NF:每一列不可包含多个值)      所谓第一范式(1NF)是指数据库表的每一列都是不可分割的基本数据项,同一列

第三篇--Jmeter测试数据库Mysql

Jmeter模拟100用户访问Mysql数据库 1.将Mysql数据库的驱动[mysql-connector-java-5.1.15-bin.jar]放到jmeter的lib目录下,新建线程组100[模拟100用户],循环次数10次,10s内启动所有线程, 如下图: 2.右键-配置元件中选择[jdbc Connection Configuration],Variable Name配置自定义名称CSMSDatabase,配置数据库最大连接数和数据库配置信息,如下图: 3.右键-Sampler中选择

导入MySQL测试数据库employee报错

导入MySQL测试数据库employee 报错 下载地址:https://launchpad.net/test-db/ 上传解压: [[email protected] ~]# tar xf employees_db-full-1.0.6.tar.bz2 [[email protected] ~]# cd employees_db 使用mysql命令行工具,导入建库建表语句和数据 employee.sql中是建库建表语句,默认使用的是InnoDB引擎,可以自行修改 [[email protect

mysql优化-针对zabbix数据库

mysql优化: 修改mysql的root账号的密码: 先停止mysql服务: service mysqld stop 使用--skip-grant-tables忽略密码启动: mysqld_safe --skip-grant-tables & 进入mysql修改密码: use mysql update user set password=password('mysql') where user='root'; flush privileges; 查看表占用空间情况: select table_