myisamchkはテーブル名または.MYIファイル名を引数に取れるので、
$ find ./ -name "*.MYI" -exec myisamchk --silent -rq {} \;
datadirにcdしてこれだけでMyISAMなテーブルを順番にmyisamchkできる。
あー、InnoDBつかいたーい。
$ find ./ -name "*.MYI" -exec myisamchk --silent -rq {} \;
With LOAD DATA LOCAL INFILE, data-interpretation and duplicate-key errors become warnings and the operation continues because the server has no way to stop transmission of the file in the middle of the operation. For duplicate-key errors, this is the same as if IGNORE is specified. IGNORE is explained further later in this section.
Treatment of empty or incorrect field values differs from that just described if the SQL mode is set to a restrictive value. For example, if sql_mode='TRADITIONAL, conversion of an empty value or a value such as 'x' for a numeric column results in an error, not conversion to 0. (With LOCAL, warnings occur rather than errors, even with a restrictive sql_mode value, because the server has no way to stop transmission of the file in the middle of the operation.)http://dev.mysql.com/doc/refman/5.6/en/load-data.html
LOAD DATA INFILE ... REPLACE INTO ...
はWarningsがあるとabortする、という仕様だった。意図したものなのかどうかはわからないけど。
— dupont (@dupont_kedama) 2014, 8月 19
$ echo -e "1\tone" > /tmp/test mysql56> CREATE TABLE t1 (num int); Query OK, 0 rows affected (0.07 sec)
mysql56> SELECT @@sql_mode; +------------------------+ | @@sql_mode | +------------------------+ | NO_ENGINE_SUBSTITUTION | +------------------------+ 1 row in set (0.00 sec) mysql56> LOAD DATA LOCAL INFILE '/tmp/test' INTO TABLE t1; Query OK, 1 row affected, 1 warning (0.00 sec) Records: 1 Deleted: 0 Skipped: 0 Warnings: 1 mysql56> SHOW WARNINGS; +---------+------+---------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------------------------------------+ | Warning | 1262 | Row 1 was truncated; it contained more data than there were input columns | +---------+------+---------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql56> TRUNCATE t1; Query OK, 0 rows affected (0.03 sec) mysql56> LOAD DATA LOCAL INFILE '/tmp/test' REPLACE INTO TABLE t1; Query OK, 1 row affected, 1 warning (0.01 sec) Records: 1 Deleted: 0 Skipped: 0 Warnings: 1 mysql56> SHOW WARNINGS; +---------+------+---------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------------------------------------+ | Warning | 1262 | Row 1 was truncated; it contained more data than there were input columns | +---------+------+---------------------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql56> SELECT @@sql_mode; +---------------------+ | @@sql_mode | +---------------------+ | STRICT_TRANS_TABLES | +---------------------+ 1 row in set (0.00 sec) mysql56> LOAD DATA LOCAL INFILE '/tmp/test' INTO TABLE t1; Query OK, 1 row affected, 1 warning (0.00 sec) Records: 1 Deleted: 0 Skipped: 0 Warnings: 1 mysql56> show warnings; +---------+------+---------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------------------------------------+ | Warning | 1262 | Row 1 was truncated; it contained more data than there were input columns | +---------+------+---------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql56> LOAD DATA LOCAL INFILE '/tmp/test' REPLACE INTO TABLE t1; ERROR 1262 (01000): Row 1 was truncated; it contained more data than there were input columns
318 /* We can't give an error in the middle when using LOCAL files */ 319 if (read_file_from_client && handle_duplicates == DUP_ERROR) 320 ignore= 1;
Breakpoint 1, mysql_load (thd=0x36c9430, ex=0x7f217c373170, table_list=0x7f217c373200, fields_vars=..., set_fields=...,
set_values=..., handle_duplicates=DUP_ERROR, ignore=false, read_file_from_client=true)
at /home/yoku0825/mysql-5.6.20/sql/sql_load.cc:190
190 {
(gdb) p thd->query_string->string->str
$3 = 0x7f217c373080 "LOAD DATA LOCAL INFILE '/tmp/test' INTO TABLE t1"
Breakpoint 1, mysql_load (thd=0x36c9430, ex=0x7f217c373180, table_list=0x7f217c373210, fields_vars=..., set_fields=...,
set_values=..., handle_duplicates=DUP_REPLACE, ignore=false, read_file_from_client=true)
at /home/yoku0825/mysql-5.6.20/sql/sql_load.cc:190
190 {
(gdb) p thd->query_string->string->str
$2 = 0x7f217c373080 "LOAD DATA LOCAL INFILE '/tmp/test' REPLACE INTO TABLE t1"
$ ./configure CFLAGS=-O3 CXXFLAGS=-O3 PKG_CONFIG_PATH=/usr/groonga/3.1.0.20131209/lib/pkgconfig --with-mysql-source=/usr/local/src/percona-server-5.6.19-67.0 --with-mysql-config=/usr/local/percona5619/bin/mysql_config checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p .. checking mysql source... yes checking mysql_config... /usr/local/percona5619/bin/mysql_config checking for libmysqlservices.a directory... configure: error: libmysqlservices.a is not found in </usr/local/percona5619/lib/mysql/> and </usr/local/percona5619/lib/mysql/mysql/>
$ ll /usr/local/percona5619/lib/libmysqlservices.a -rw-r--r-- 1 root root 15662 7月 1 18:20 /usr/local/percona5619/lib/libmysqlservices.a
$ /usr/local/percona5619/bin/mysql_config --variable=pkglibdir /usr/local/percona5619/lib/mysql $ ll /usr/local/percona5619/lib/mysql 合計 1372 lrwxrwxrwx 1 root root 16 8月 7 12:10 libjemalloc.so -> libjemalloc.so.1 -rwxr-xr-x 1 root root 1395722 7月 1 18:26 libjemalloc.so.1 drwxr-xr-x 2 root root 4096 8月 7 16:32 plugin
$ diff -c configure.orig configure
diff -c configure.orig configure
*** configure.orig Thu Aug 7 17:18:35 2014
--- configure Thu Aug 7 17:18:45 2014
***************
*** 18363,18369 ****
*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libmysqlservices.a directory" >&5
$as_echo_n "checking for libmysqlservices.a directory... " >&6; }
! pkglibdir="$($ac_mysql_config --variable=pkglibdir)"
mysql_build_libservices_dir="${MYSQL_BUILD_DIR}/libservices"
if test -f "${mysql_build_libservices_dir}/libmysqlservices.a"; then
mysql_services_lib_dir="${mysql_build_libservices_dir}"
--- 18363,18369 ----
*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libmysqlservices.a directory" >&5
$as_echo_n "checking for libmysqlservices.a directory... " >&6; }
! pkglibdir="/usr/local/percona5619/lib"
mysql_build_libservices_dir="${MYSQL_BUILD_DIR}/libservices"
if test -f "${mysql_build_libservices_dir}/libmysqlservices.a"; then
mysql_services_lib_dir="${mysql_build_libservices_dir}"
$ ./nagios_for_mysql.pl --user root --password xxxx --host 127.0.0.1 --port 64056 --sql "SELECT COUNT(*) FROM information_schema.processlist WHERE state IN ('update', 'updating') AND time > 10" --warning 10 --critical 20
$ echo $?
3
$ perl ./nagios_for_mysql.pl --user root --host 127.0.0.1 --port 64056 --sql "SELECT table_rows FROM information_schema.tables WHERE table_schema = 'mysql' AND table_name = 'user'" $ echo $? 0
$ perl ./nagios_for_mysql.pl --user root --host 127.0.0.1 --port 64056 --sql "SELECT variable_value FROM information_schema.global_status WHERE variable_name = 'sort_merge_passes'" --warning 2 --critical 10 $ echo $? 0
@yoku0825 機能見てないけど、クエリ書けるpluginありますね https://t.co/Mb14xJqqyf
— masahiro nagano (@kazeburo) 2014, 7月 30
mysql56> show create table Country\G
*************************** 1. row ***************************
Table: Country
Create Table: CREATE TABLE `Country` (
`Code` char(3) NOT NULL DEFAULT '',
`Name` char(52) NOT NULL DEFAULT '',
`Continent` enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia',
`Region` char(26) NOT NULL DEFAULT '',
`SurfaceArea` float(10,2) NOT NULL DEFAULT '0.00',
`IndepYear` smallint(6) DEFAULT NULL,
`Population` int(11) NOT NULL DEFAULT '0',
`LifeExpectancy` float(3,1) DEFAULT NULL,
`GNP` float(10,2) DEFAULT NULL,
`GNPOld` float(10,2) DEFAULT NULL,
`LocalName` char(45) NOT NULL DEFAULT '',
`GovernmentForm` char(45) NOT NULL DEFAULT '',
`HeadOfState` char(60) DEFAULT NULL,
`Capital` int(11) DEFAULT NULL,
`Code2` char(2) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql56> EXPLAIN SELECT Code, Name, Population FROM Country WHERE Continent = 'Asia';
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | Country | ALL | NULL | NULL | NULL | NULL | 239 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
my @country_table= ({Code => "ABW", Name => "Aruba", Continent => "North America", .., Population => 103000},
{Code => "AFG", Name => "Afghanistan", Continent => "Asia", .., Population => 22720000},
{Code => "AGO", Name => "Angola", Continent => "Africa", .., Population => 12878000},
..);
foreach my $row (@country_table)
{
if ($row->{Continent} eq "Asia")
{
printf("Code:%s, Name:%s, Population:%d\n", $row->{Code}, $row->{Name}, $row->{Population});
}
}
mysql56> EXPLAIN SELECT Code, Name, Population FROM Country WHERE Continent = 'Asia'; +----+-------------+---------+------+---------------+-----------+---------+-------+------+-----------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+------+---------------+-----------+---------+-------+------+-----------------------+ | 1 | SIMPLE | Country | ref | Continent | Continent | 1 | const | 51 | Using index condition | +----+-------------+---------+------+---------------+-----------+---------+-------+------+-----------------------+ 1 row in set (0.01 sec)
my @country_table= ({Code => "ABW", Name => "Aruba", Continent => "North America", .., Population => 103000},
{Code => "AFG", Name => "Afghanistan", Continent => "Asia", .., Population => 22720000},
{Code => "AGO", Name => "Angola", Continent => "Africa", .., Population => 12878000});
my %continent_index= (Asia => [1, 9, 19, ..],
Europe => [4, 5, 15, ..],
..);
foreach my $row_num (@{$continent_index{Asia}})
{
printf("Code:%s, Name:%s, Population:%d\n",
$country_table[$row_num]->{Code},
$country_table[$row_num]->{Name},
$country_table[$row_num]->{Population});
}