zortje / mysql-keeper

在MySQL数据库中查找错误的配置或遗漏的优化机会

0.4.0 2015-02-22 00:33 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:55:30 UTC


README

在MySQL数据库中查找错误的配置或遗漏的优化机会。

Packagist Travis branch Scrutinizer branch Scrutinizer Dependency Status Packagist

SensioLabsInsight

功能

检测以下问题

  • 重复索引
  • 自动递增列上缺少主键
  • 主键上的冗余唯一索引
  • 主键上的冗余键索引
  • 表和列之间不一致的校对使用

通过Composer安装

安装MySQL Keeper的推荐方式是通过Composer

{
    "require": {
        "zortje/mysql-keeper": "~0.0"
    }
}

用法

$pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp', 'root', '');

$database = DatabaseFactory::create($pdo);
$databaseResult = $database->getResult();

$databaseResult数组看起来可能如下,第一层键是表名。

[
	'users' => [
		'issues' => [
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Set as auto_increment but has no primary key'
			],
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Set as auto_increment but is not set as primary'
			]
		],
		'optimizations' => [
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Field should be unsigned, as no field values are negative'
			]
		]
	]
];

与Melody一起使用

Melody 允许简单地执行PHP脚本来执行内联Composer要求。

mysql-keeper_myapp.php

<?php

<<<CONFIG
packages:
    - "zortje/mysql-keeper": "~0.0"
CONFIG;

$pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp', 'root', '');

$database = Zortje\MySQLKeeper\DatabaseFactory::create($pdo);

print_r($database->getResult());

只需运行

$ melody run mysql-keeper_myapp.php