å ¨å½1å2000ä¸ã® Docker ãã¡ã³ã®çããããã«ã¡ã¯ã MySQL ã®èµ·åãã¨ã¦ã¤ããªãé ãã®ã¯æåãªè©±ã ã¨ããã Docker ã³ã³ããã®èµ·åã¯ãªããªãæ©ãã®ã§ã MySQL ã使ã£ã¦ãããããªãã¹ããé«éåããã±ã¼ã¹ã§æç¨æ§ãèªããããã®ã§ã¯ãªããã¨æã£ã¦ PoC ãæ¸ãã¦ã¿ãã ï¼å®£ä¼ï¼ãããã£ã話ãå«ã㦠YAPC ã§ãã¼ã¯ãããã®ã§ SNS ç㧠upvote ãé¡ããã¾ãï¼ ( â'Ï')â 楽ããã¢ãã«å±¤éçº - YAPC::Asia Tokyo 2014 ï¼å®£ä¼ãããï¼ MySQL ã使ã£ããã¹ã MySQL ã使ã£ããã¹ããããå ´åãã ããã次㮠2 ãã¿ã¼ã³ã«ãªãã MySQL ããã¹ãã®ãã³ã«èµ·åãã¦ã¯ãªã¼ã³ãªç¶æ ã§ä½¿ã ãã¼ã«ã«ã«ãã¼ã¢ã³ã¨ãã¦èµ·åãã MySQL ã«æ¥ç¶ã㦠DROP TABLE ã TRUNCATE ã§ã¯ãªã¼ã³ãªç¶æ ã«ãã¦ä½¿ã ã ãã©ã
MySQL::Partitionããªãªã¼ã¹ãã¦ããã®ã§ãç¥ããã§ãããã¼ãã£ã·ã§ã³ãåãç¨ã®SQLãçæãã¦ãããã¯ã¨ãªãã«ãã¼ã§ãã Webãµã¼ãã¹ã§ã¯å¦ä½ã«ãã¼ã¿ãå¢ãããªãããDBãåå²ããªãã§ä¸ç³»çµ±ã«æããããDBãã¡ã¢ãªã«å¦ä½ã«è¼ããããã£ã¦ã®ããããµããµã¼ãã¹éç¨ããã¦ããä¸ã§éè¦ã§ããMySQLã使ã£ã¦ããå ´åããã®ããã«é常ã«æç¨ãªã®ããã¼ãã£ã·ã§ã³ã§ãé©åã«ãã¼ãã£ã·ã§ã³ãåããå¤ããã¼ã¿ãéæDropãã¦ãããéç¨ã«è½ã¨ãããã®ãé常ã«å¤§åãªããã§ãã 社å ã®ããã¸ã§ã¯ãã§ãPartitionãæ´»ç¨ãã¦ããããã§ããããã¾ãã¡ä»çµã¿åããã¦ããããå¤ãããã¸ã§ã¯ãããã³ãããéãã¦ç§ä¼ã®ã¿ã¬åãã¦ãããä¾ãã°ãã¤ãªã¼ã§ãã¼ãã£ã·ã§ã³ãåãå ´åãMySQL5.5ããã¯RANGE COLUMNSãã¼ãã£ã·ã§ã³ã使ããã«ãé¢ããããTO_DAYS()ã¨ããæªã ã«ã³ãããã¦ä½¿ã
#5ãGitDDLã¾ãã¤ããã¼ãã£ãã tech.kayac.com Advent Calendar 2012 | tech.kayac.com - KAYAC engineers' blog ã便å©ããã ãªã¼ã¨æã£ã¦ã ã§ãGitã¨çµ¡ããªãã¦ããWebã¢ããªã«ããã¦ãç¾å¨ã®ç°å¢ã§ä½¿ç¨ãããã¼ã¿ãã¼ã¹ãã¨ãæãã¹ãã¹ãã¼ãã®ç¶æ ã示ãDDLãã¡ã¤ã«ãã®å·®åãåã£ã¦åãããã¨ãã§ããã°ããã ãã§åå使ããæ°ããããã¨æã£ã¦ä¸ã¤ã®éç¨æ¹æ³ãèãã¦ã¿ãã ãã¡ããGitDDL使ã£ã¦ãè¯ãã®ã ãã©ãSQL::Translatorã使ãã ãã§ãããç¨åº¦ã¯ãã¨ãããã¨ã§ã Amon2ããã¸ã§ã¯ãã®ä¾ã§ã åæè¨å® $ amon2-setup.pl MyAppã¨ãã§éå½¢ããã¸ã§ã¯ããä½ãã¨ãsqlãã£ã¬ã¯ããªãä½ããã¦ãããã«DDLãä¿åããé°å²æ°ã«ãªãããã®ã¾ã¾sql/mysql.sqlã使ã£ã¦ããã
ç°å¢ ubuntu lampp perl DBI DBD::mysql perl㧠DBI->connect()ãããã¨ããã failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at insert.pl line 11 ã¨ãããããªã¨ã©ã¼ãçºçãã¦è»½ãã¤ã¾ã£ãã å¤ãã®äººã ãDBIã§Can't connect to local MySQL server through socket '/tmp/mysql.sock'ã http://diary.lampetty.net/20060926.html ã«ã¦è§£æ±ºãã¦ãããèªåã¯ãã¡ã ã£ãã my.cnfãæ¸ãç´ãã¦ãã perlã®åºåããã¨ã©ã¼ã¯ä¾ç¶ã¨ã㦠failed: Can't connect to l
% carton exec -Ilib â prove -lv t/mysqld.t *** mysqlinstalldb failed *** Canât locate lib/core/only.pm in @INC (⦠çµè«ããè¨ãã¨ãcarton execããperlã¨å¥ãã¼ã¸ã§ã³ã®perlãã©ããã§ä½¿ããã¦ã ãã®Perlã«local::lib(lib::core::only)ãå ¥ã£ã¦ããªãã¨æ»ã¬ã Test::mysqldã ã¨ãmysql_install_dbã£ã¦ããMySQLã®ã³ãã³ããããã¯ãã¦ãã ãã ãã©ããããå®ã¯perlã¹ã¯ãªããã§ã/usr/bin/perlã£ã¦shebangã«æ¸ããã¦ã㦠System perlåæã«ãã¦ããã®ã ãã©ãããã«local::libãå ¥ã£ã¦ããªãã¨ã³ã±ãã Carton:CLI#cmd_execã®ä¸ã§PERL5OPTã以ä¸ã®ããã«ã»
å æ¥DBIã使ã£ã¦ãã¦ãè¬ãªæåã«ééããã®ã§æ¸ãã¦ã¿ããLIMIT, OFFSETå¥ã§ãã¬ã¼ã¹ãã«ãã¼ãç¨ããæã«èµ·ãã£ããDBI + DBD::mysqlã使ã£ã¦ããã DBI: 1.616 DBD::mysql: 4.022 LIMITã¨OFFSETã両æ¹ã«ãã¬ã¼ã¹ãã«ãã¼ã使ã LIMITã¨OFFSETã両æ¹ã?ã«ããã®ã¯ãã¾ãããã $res = $dbh->prepare_cached(q[ SELECT * FROM user WHERE name = ? LIMIT ? OFFSET ? ])->execute('shiba_yu36', 1, 1); LIMITã®ã¿ãã¬ã¼ã¹ãã«ãã¼ LIMITã®ã¿?ã§ããã¾ãããã $res = $dbh->prepare_cached(q[ SELECT * FROM user WHERE name = ? LIMIT ? OFFSET
æ°ããæ©è½ããªãªã¼ã¹ããéã«ãMySQLã«å¯¾ãã¦å¹ççã§ã¯ãªãã¯ã¨ãªãçºè¡ããã¦ãã¾ã£ã¦ããããç©ãã£ã¦ãµã¼ãã¹å ¨ä½ã«å½±é¿ãåºã¦ãã¾ãåã«çºè¦ãã¦ã¢ã©ã¼ããããããã çºè¦ããæç«ã¦ã¨ãã¦ã¯CPU使ç¨çãInnoDBã®ROW OPERATIONSãèããããã¨ããã§ãããä»åã¯ã¹ãã¼ã¯ã¨ãªãçºçããåæ°ãç£è¦ãããã¨ã«ãããã¡ãªã¿ã«ãã¤ãã®ãã¨ãªãã対象ã¨ããMySQLã¯4.0ç³»ãlong_query_timeããªã³ã©ã¤ã³ã§å¤æ´ã§ãã¾ãããããã¯ã MySQLã®ã¹ãã¼ã¯ã¨ãªãçºçããåæ°ã¯ãshow status ã®Slow_queriesã¨ããé ç®ã§ã¿ããã¨ãã§ã㦠mysql> show status like 'Slow_queries'; +---------------+-------+ | Variable_name | Value | +---------------+---
id:zigorou å çã«æãã¦ããã£ãæãã¡ã¢ã (ãã¨ã§èª¿ã¹ã¦ã¿ãã http://perl-users.jp/articles/advent-calendar/2010/hacker/1 ã§ãã§ã«è¨åããã¦ãã¾ããããSQLå©ããã¨ããã¨ããã ã強調ãã¦åæ²) ã¾ããã¹ããç¨æãã¾ãã [kawamoto.m@mm1:~]$ cat 01.t use Test::More; use Test::mysqld; my $mysqld = Test::mysqld->new( my_cnf => { 'skip-networking' => '', # no TCP socket } ) or plan skip_all => $Test::mysqld::errstr; ok(1); done_testing;perl -d ã§testãèµ°ããã¾ãã [kawamoto.m@mm1:
perlã§ãã¼ã¿ãã¼ã¹ã使ãæã«èª°ããå¿ ã使ãDBIããã®æ¥ç¶æã«ä½¿ãconnectã¡ã½ããã®ç¬¬4å¼æ°ã«è¨å®ãã¦ãããªãã·ã§ã³ããµã¼ãã¹ã«ããã¾ã¡ã¾ã¡ãªãã ãã©ãã ããéæ¿è¨å®ãæãã¦ãã ããã åã使ãã®ãã my $dbh = DBI->connect($dsn, $user, $password, { AutoCommit => 1, PrintError => 0, RaiseError => 1, ShowErrorStatement => 1, AutoInactiveDestroy => 1, }); ããã å ãã¦ãmysqlã§ããã° mysql_enable_utf8 => 1 mysql_auto_reconnect => 0, SQLiteã 㨠sqlite_unicode => 1 sqlite_use_immediate_transaction => 1 ã追å ã
ã¯ãã¾ãã¯ãã¯ã æè¿ããã¾ãã³ã¼ãæ¸ãã¦ã¾ãããlestrratã§ãã ãã¹ããèµ°ãããæã«ããããªä»ã®ãã¼ã¢ã³ãç«ã¡ä¸ãããããã®ãã¹ãã®ããã ãã®è¨å®ãå ã«ããªãã¨ãããªãã£ããã¨ãè²ã ããã¾ããããçµæ§é·ãéMakefile.PLã¯Module::Installã§æ¸ãã¦ããããããã£ã¦ãã¡ãã£ã¨åã«xaicronãããæ¸ãã¦ãModule::Install::TestTargetã§ãã«ããã«ããã£ã¦ãã®ã§ãããã¡ãã£ã¨åã«Yappo/tokuhiromãããproveã§æ¸ãã¦ãã»ããã¢ãããã¾ãã£ã¨èªåã®æ¬²ããç¨éã«ã使ããäºã«æ°ã¥ããã®ã§ããããªã¢ããªã±ã¼ã·ã§ã³ã®ãã¹ãããã®ããã«å¤ãã¦ã¿ã¾ããã æµã proveã§ãã¹ããããã¨ãproveã®ãã©ã°ã¤ã³ãå¼ã³åºãè¨å®ãã§ããã®ã§ãããããããã©ã°ã¤ã³ã¨ãããããã¹ãåã«å®è¡ãããããã¯ã¨ãã¦å©ç¨ããäºã«ãã£ã¦ä»»æã®è¨å®ç¨ã®ã³ã¼ã
ã¨ã«ãã楽ã«ããæ°è»½ã«ããæ°è»½ã«ãã¹ãã追å ã§ãã¦ããæ°è»½ã«ãã¹ããå®è¡ã§ãããã¨ããã®ããªã«ãããéè¦ã§ãã 追å ãããã¨ããã£ãã¨ãã«ãã©ã追å ããããããããããªããã¨ããç¶æ³ã«ãªããã¡ãªã®ã§ãããããããããããªæ§æè¦ç´ ãã¨ã«ãã¹ããã²ã¨ã¨ããããã¦ã¿ãã¨ããã®ãéè¦ã ã¨ãããã¾ããO/R Mapper ã®ã¯ã©ã¹ã®ãã¹ãã¨ããmodel ã®ãã¹ãã¨ããã³ã³ããã¼ã©ã®ãã¹ãã¨ããJSON API ã®ãã¹ãã¨ããã ExtUtils::MakeMaker ã§ãã¹ãããããããªãExtUtils::MakeMaker ãç´ ã§ã¤ãã㨠blib/ ã¨ãã¤ãã£ã¦ãã¦ãããã®ã§ãMakefile.PL ã«ä»¥ä¸ã®ãã㪠hack ãã»ã©ããã¦ããã¾ããã¦ã§ãã¢ããªã±ã¼ã·ã§ã³ã§ blib/ ã¨ãã«ã³ãã¼ããå¿ è¦ãªãã§ããããå®éç¨ã§ã blib/ ã§ãããããªãããã¤ã³ã¹ãã¼ã«ããã¾ãããã #
Test::mysqldã¨ãã§ãã¹ãèµ°ãããæã«éè¡ã£ãããããªäºã Test::mysqldã使ãã¨ã¯ã¼ã«ã«MySQLãèµ·åãããããã®ã§ãããã使ããã¨ãããã ãã§ããããã®ãã¼ã«ã«ã«ããmysqlãMacPortsã®mysqlã§ããã¡ã¤ã«ã¬ã¤ã¢ã¦ããã¡ã¿ã¡ã¿ãªãã ãã ããã¾ããããªæãã§ãTest::mysqldãç¶æ¿ããMyApp::Test::mysqldãæ¸ãããããï¼ å¿ è¦ã¨ããã°MacPortsã¨ãã®ç°å¢ãããªãã¦ãMYSQL_INSTALL_DBã¨MYSQLDãè¨å®ããã°ãã¹ãæã«Test::mysqldãè¦ããã¤ããªãå¤æ´ã§ããã®ããã½ã ãï¼ ãã¦ãããã使ã£ã¦ããä½åããã¹ãã¹ã¯ãªãããããæã«ä¸åä¸åmysqlãç«ã¡ä¸ãç´ãã¦ã¡ãæå³ããªããé ãããæ¯åDBã®è¨å®ãããªãã¡ããããªããããªããï¼ ã ããã§ãã¾ãmake testãèµ°ãã¨ãã«åãã£ã¦Test::mys
DBD::mysqlã®4.020ãæ¨æ¥ãªãªã¼ã¹ããã¾ããã ãã®ãªãªã¼ã¹ã«ã¯mysql_server_prepare=1ã使ã£ã¦ããå ´åã®ãã°ã®ä¿®æ£ã5件ã»ã©å«ã¾ãã¦ãã¾ãã(ChangeLog) DBD::mysql 㧠mysql_server_prepare=1 ã®ã¨ã TEXT åã®æ¬ãèªå utf8::decode ãããªããªã ãã¡ãã®ããã°ã§ææããã¦ãã件ãç´ãã¦ããããéããã¨æã£ã¦ããããã«mysql_server_prepare=1ã®ç¶æ ã§DBD::mysqlã®ãã¹ããå®è¡ããã失æãã¾ãã£ããããããé§ç®ãããããªãã¨æã£ãã®ã§ãããä½æ ãmysql_server_prepareã¨å¿ä¸ããè ¹ããããä¸å¿ãã¹ã¦ã®ãã¹ããéãããã«ããããéãã¾ãã£ã¦ã¿ãã¨ããåãè¾¼ã¾ããã¨ããæãã«ãªãã¾ããã(ãªãªã¼ã¹å¾ã«2ã¤ã»ã©ããã«pull reqãã¦ãã¾ããâ¦ã) TEXTå
DBIx::Skinnyã§ç°¡åã«ä½¿ããpagerãå®è£ ããã¦ããªã主ãªçç±ã¯ã http://perl-users.jp/articles/advent-calendar/2009/dbix-skinny/19.html ã¨ãã«æ¸ãã¦ãããã§ããã 管çç»é¢ã«ãããã¡ãª ãã¼ã¿ãæ§ã ãªæ¡ä»¶ã§æ¤ç´¢ãããã¼ã¸ã¿ãããªã®ãæ¸ãã¨ãã«ã¯SQLãç´æ¸ãããã®ã¯ã¤ããã¦ãDBICã¿ããã«resultsetãæ¡ä»¶ã«ãã£ã¦whereç¯ã追å ããã®ã楽ãªãã¨ãããã¾ãããããããã¼ã¸ã«éã£ã¦pagingã®å¦çã¯å¿ è¦ã«ãªããã©ãã²ã¨ã¤ã²ã¨ã¤SQLãç´æ¥æ¸ãã¦Pagerãçæããã¨ããªã£ã¦ããã¨ãªããªãããã©ãããã§ãã http://d.hatena.ne.jp/nekokak/20090924/1253761408 ã¨ãããã®ãselectãããã³ã«æ¸ãã¦ãã¨ãã¡ãã£ã¨ãã¡ããã¡ããã¦è¦ã«ããããçµæ§é·ãã¦
id:xaicron æ°ãç´¹ä»ãªããã¦ãã¾ãã make test 㧠Test::mysqld ãæ°¸ç¶åãããæ¹æ³ ãæ©éå°å ¥ãã¦ããã®ã§ãããmake test ã¯éããªã£ã¦ä¾¿å©ãªã®ã§ãããprove 㧠1 ã¤ãã¤ãã¹ããããã¨ãã¯ãç¸å¤ããã mysqld ãæ¯åãèµ·åã»çµäºããã®ã§æéãããã£ã¦éçºæã®ã¹ãã¬ã¹ã«ãªãã¾ãã ããã§ãéçºæã«ã¯å¥ã¦ã£ã³ãã¦ã§ mysqld ãç«ã¡ä¸ãã¦ããã¦ãããã«æ¥ç¶ãã«è¡ãããã«ããã°å¤§åå¿«é©ã«ãªãã¨æããå®è£ ãã¦ã¿ã¾ããã #!/usr/bin/env perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use File::Spec; use JSON; use Test::MyApp::mysqld; my $tempfile = File:
å®éã«ã©ããã£ã¦ãã®ããªã¼ã£ã¦è©±ãããã¾ããã¦ãªãã£ãã®ã§ã ã¾ãããããªæãã®ã¢ã¸ã¥ã¼ã«ã t/lib/Test/MyApp/mysqld.pm ã¨ãã§ä½ã£ã¦ M::I::TestTarget ã® default_test_target() 㧠`make test` ãæ¸ãæãã¦ãããt/script/setup_mysqld.pl ã« ã¨ãæ¸ãã¦ããã¾ãã ããããã®ãã¹ãã§ã¯ãTest::MyApp::mysqld->setup 㧠mysqld ãç«ã¡ä¸ããããã«ãã¦ç½®ãã°ã prove ã§åå¥ã«ãã£ãæã¯ãããããç«ã¡ä¸ãã make test ããã¨ãã¯ãæåã«ç«ã¡ä¸ãã¦ããã¨ã¯ä½¿ãã¾ãã ã¨ããæãã«ãªãã¾ãã ãã¤ã³ãã¨ãã¦ã¯ã $ENV{TEST_MYSQLD} ã« Test::mysqld ã®ãã¼ã¿æ§é ããã®ã¾ã¾ JSON ã«ãã¦çªã£è¾¼ã Test::MyApp::m
æ£è¦è¡¨ç¾ã§ãã ^a_c.* ã¿ãããªã®ãã²ã£ããããã¨æã£ã¦ï¼ my ($sql, @binds) = SQL::Abstract->new()->select( # table 'foo', # fields [ '*' ], # where { id => { LIKE => 'a_c%' }, }, ); ã¿ããããã¨ï¼a_code ã ãã§ãªã abc ãããããã¦ãã¾ãç½ ã PostgreSQL ã ã¨ï¼ããã©ã«ãã§ã¨ã¹ã±ã¼ãæåã \ ã«ãªã£ã¦ãã®ã§ï¼ # where { id => { LIKE => 'a\\_c%' }, }, ã®ããã«ã¨ã¹ã±ã¼ãããã°ããï¼MySQL ã ã¨ã©ããªãã ãï¼ã ã§ãï¼ãã¨ãã° SQLite ã¯ããã©ã«ãã§ã¨ã¹ã±ã¼ãæåãè¨å®ããã¦ãªããã ãã LIKE ãªã©ã®ãã¨ã« ESCAPE ãæå®ããã®ãæ¬çããªãã ãã©ï¼SQL::Abstract ã§ãµ
ãããã®è¨äºãèªãã æ¹ãä¸è¨ã®ãããªã¨ã©ã¼ã¡ãã»ã¼ã¸ã§ã¤ã³ã¹ãã¼ã«ã§ããªãã§ããã®ã§ããã°ããã£ã¨å¾è¿°ã®è§£æ±ºçã§ãã¾ãããã§ãããt/80procs.t ................. 1/29 DBD::mysql::db do failed: alter routine command denied to user ''@'localhost' for routine 'test.testproc' at t/80procs.t line 41.DBD::mysql::db do failed: alter routine command denied to user ''@'localhost' for routine 'test.testproc' at t/80procs.t line 41.ãã®ã¡ãã»ã¼ã¸ã¯ããã¹ãã¹ã¯ãªãããDBã«æ¥ç¶ãã«ããéã®ã¦ã¼ã¶åãè¨å®ããã¦ã
DBD:a:mysqlãinstallããéãåç´ã«å®è¡ããã¨ãã¨ã©ã¼ã§æããã¦ãã¾ãã¾ãã ä¾ãã°ãperl Makefile.PLã§ã¯... $ cd DBD-mysql-4.010 $ /usr/local/bin/perl Makefile.PL Can't exec "mysql_config": No such file or directory at Makefile.PL line 76. ï¼ç¥ï¼ä¾ãã°ãmake testã§ã¯... $ make test ï¼ç¥ï¼ t/76multi_statement.........ok t/80procs...................ok 1/29DBD::mysql::db do failed: execute command denied to user ''@'localhost' for routine 'test.t
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}