MySQL

¹¹¿·Æü 2010-11-26 (¶â) 21:59:44

MySQL¤Î¥¤¥ó¥¹¥È¡¼¥ë

MySQL¤Î¥½¡¼¥¹¤ò¤³¤³¤Î²¼¤Î¤Û¤¦¤ÎSource downloads¤«¤éDownload.

$ su
# /usr/sbin/useradd mysql

home¥Ç¥£¥ì¥¯¥È¥ê¤ò/usr/local/var¤ËÊѹ¹

$ tar zxvf mysql-4.1.12.tar.gz
$ cd mysql-4.1.12
$ ./configure --with-charset=ujis -with-extra-charsets=all \
--with-mysqld-user=mysql
--with-charset
¥Ç¥Õ¥©¥ë¥È¤Ç»ÈÍѤµ¤ì¤ëʸ»ú¥³¡¼¥É¤ò»ØÄꤷ¤Þ¤¹¡£EUC¤Ê¤éujis¡¢Shift-JIS¤Ê¤ésjis¡¢UTF8¤Ê¤éutf8
--with-extra-charset
¥Ç¥Õ¥©¥ë¥È¤Ç»ØÄꤵ¤ì¤¿Ê¸»ú¥³¡¼¥É°Ê³°¤ò¥µ¥Ý¡¼¥È¤·¤¿¤¤¾ì¹ç¤Î»ØÄê¤Ç¤¹¡£
"--with-extra-charset=ujis,sjis,..."¤Î¤è¤¦¤Ë¸ÄÊ̤˻ØÄê¤Ç¤­¤Þ¤¹¤¬¡¢
¤³¤³¤Ç¤Ï¡Èall¡É¤È¤·¤Þ¤¹¡£¤³¤Î¥ª¥×¥·¥ç¥ó¤ò»ØÄꤹ¤ë¤³¤È¤Ç¡¢
make¤ò¤·Ä¾¤µ¤º¤È¤â¡¢°Û¤Ê¤ëʸ»ú¥³¡¼¥É¤Ç¥µ¡¼¥Ð¤òµ¯Æ°¤¹¤ë¤³¤È¤¬²Äǽ
--with-mysqld-user
MySQL¥Ç¡¼¥â¥ó¤òµ¯Æ°¤¹¤ë¥æ¡¼¥¶¡¼¤Î»ØÄê
$ make
$ su
# make install
# cp support-files/my-medium.cnf /etc/my.cnf  <---(1)

(1)¤Ç¥³¥Ô¡¼¤¹¤ë¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤Æ

¥Õ¥¡¥¤¥ë̾»ÈÍÑÍÑÅÓ
my-small.cnf64MB°Ê²¼¤Î¥á¥â¥ê¤òÅëºÜ¤·¤¿PC
my-medium.cnf128MB°Ê²¼¤Î¥á¥â¥ê¤òÅëºÜ¤·¤¿PC
my-large.cnf512MB°Ê²¼¤Î¥á¥â¥ê¤òÅëºÜ¤·¤¿PC
my-huge.cnf1GB¡Á2GB°Ê²¼¤Î¥á¥â¥ê¤òÅëºÜ¤·¤¿PC
my-innodb-heavy-4G.cnf4GB¤Î¥á¥â¥ê¤ÈInnoDB¤ÇºîÀ®¤µ¤ì¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤è¤Ã¤Æ¹½ÃÛ¤µ¤ì¤¿PC

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î½é´ü²½

°Ê²¼¥Ç¡¼¥¿¥Ù¡¼¥¹¥³¥Þ¥ó¥É¤òroot¤Ç¹Ô¤Ã¤Æ¤¤¤ë¤¬¥·¥¹¥Æ¥à´Ø·¸°Ê³°¤Ï°ìÈ̥桼¥¶¤Ç¤âOK

# /usr/local/bin/mysql_install_db --user=mysql
Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system
(ά)
he latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at https://order.mysql.com

# /usr/local/var(¥Ç¡¼¥¿¥Ù¡¼¥¹ÊݸÀè)¤Î¥ª¡¼¥Ê¤òÊѹ¹

# chown -R mysql.mysql /usr/local/var

µ¯Æ°

# /usr/local/bin/mysqld_safe --user=mysql --log &

Æ°ºî³Îǧ

--log¤Ç/usr/local/var/(¥µ¡¼¥Ð̾).log¤Çlogfile¤¬ºîÀ®¤µ¤ì¤ë

°Ê²¼¤Î¥³¥Þ¥ó¥É¤Ç·ë²Ì¤¬°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ì¤ÐOK

# /usr/local/bin/mysqlshow
+-----------+
| Databases |
+-----------+
| mysql     |
| test      |
+-----------+

Á´¤Æ¤ÎDB¤òɽ¼¨¤¹¤ë¤Ë¤Ï(root¤Î¥Ñ¥¹¥ï¡¼¥ÉÀßÄê¸å¤Ï)

$ /usr/local/bin/mysqlshow -u root -p
Enter password:*****
+-----------+
| Databases |
+-----------+
| moodle    |
| mysql     |
| test      |
| xoops     |
+-----------+

¥Ñ¥é¥á¡¼¥¿¤Î»ØÄê

¤¿¤È¤¨¤Ð¡¢MySQL¤ÎºÇÂçÀܳ¿ô¤ò¾å¤²¤ë¤Ë¤Ï¡¢mysqld¤Ë¥ª¥×¥·¥ç¥ó¡Ö--set variable=max_connections=¥³¥Í¥¯¥·¥ç¥ó¿ô¡×¤È¤·¤Æ¤¤¤¹¤ë¤«

/etc/my.cnf¤Î

[mysqld]
max_connections = 120

¤ËÄɲ乤롣

MySQL¤ÎÄä»ß

$ /usr/local/bin/mysqladmin -u root -p shutdown

MySQL¤òÆ°¤«¤¹

MySQL¤Îroot ¤Î¥Ñ¥¹¥ï¡¼¥ÉÀßÄê

$ /usr/local/bin/mysqladmin -u root password '******' <--(1)

¾åµ­¤Îmysqladmin¤Ç¥Ñ¥¹¥ï¡¼¥É¤òÀßÄꤷ¤¿¤È¤­¤Ï°Ê²¼¤Î¥³¥Þ¥ó¥É¤Çreload¤¹¤ëɬÍפ¬¤¢¤ë

$ /usr/local/bin/mysqladmin -u root -p reload
Enter password:

root¤Î¥Ñ¥¹¥ï¡¼¥ÉÊѹ¹

$ mysqladmin -u root -p password '******'  <--NewPassword
Enter password: ******* <--OldPassword

¡Ömysqladmin -u root -p reload¡×¤¬É¬Íפ«¤ÏÉÔÌÀ

# mysql -u root -p
Enter password: <--£±(1)¤Î¥Ñ¥¹¥ï¡¼¥É¤òÆþÎÏ
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 4.1.12

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
mysql> select host,user,password from mysql.user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *3*************************************** |
| open2_06  | root |                                           |
| open2_06  |      |                                           |
| localhost |      |                                           |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)

root¤Çmysql¤Ë¥í¥°¥¤¥ó

# mysql -u root mysql

¤â¤¦¤È¤Ä¤Îroot¤Î¥Ñ¥¹¥ï¡¼¥É¤òÀßÄê(root@open2_06) SET PASSWORD ¹½Ê¸¤Ç¥Ñ¥¹¥ï¡¼¥É¤ÎÀßÄê¡£

mysql> SET PASSWORD FOR 'root'@'open2_06' = PASSWORD('*****');
Query OK, 0 rows affected (0.00 sec)

¤¹¤Ù¤Æ¤Î¤³¤È¤¬½ÐÍè¤ëspadmin¤È¤¤¤¦¥æ¡¼¥¶¤òÅÐÏ¿(¥í¡¼¥«¥ë¤Î¤ß)

mysql> GRANT ALL PRIVILEGES ON *.* TO spadmin@localhost IDENTIFIED BY 'mysql(¥Ñ¥¹¥ï¡¼¥É)' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

¥ê¥â¡¼¥È¤«¤é¤â¤¹¤Ù¤Æ¤Î¤³¤È¤¬½ÐÍè¤ë¤Ë¤Ï

mysql> GRANT ALL PRIVILEGES ON *.* TO spadmin@"%" IDENTIFIED BY 'mysql(¥Ñ¥¹¥ï¡¼¥É)' WITH GRANT OPTION;
¤ÎÄɲä¬É¬Í×(¥ê¥â¡¼¥È¤«¤é¤Îµö²Ä¤òÍ¿¤¨¤ë¤Ë¤Ï¥í¡¼¥«¥ë¤âɬÍ×)

GRAN¼Â¹Ô¸å¤Ï

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

¤òɬ¤º¼Â¹Ô

Ãí¡Ë¥æ¡¼¥¶Ì¾¤Ïmysql -u¤Ç»ØÄꤷ¤Ê¤¤¸Â¤êlogin¥æ¡¼¥¶Ì¾¤Ë¤Ê¤ë

¥Ñ¥¹¥ï¡¼¥É¤ÎÊѹ¹

mysql> SET PASSWORD FOR spadmin@localhost = PASSWORD('*******');
Query OK, 0 rows affected (0.00 sec)

¥æ¡¼¥¶ºï½ü

¥æ¡¼¥¶ºï½ü¤Ï¸¢¸Â¤òÇíÃ¥¸åºï½ü¤¹¤ë¡£¤È¤ê¤¢¤¨¤º¥í¥°¥¤¥ó¤¹¤ë

$ /usr/local/bin/mysql -u root -p mytest

¸¢¸Â¤òÇíÃ¥(revoke)

revoke ¸¢¸Â on ¥Ç¡¼¥¿¥Ù¡¼¥¹Ì¾.¥Æ¡¼¥Ö¥ë̾ from ¥æ¡¼¥¶Ì¾@¥Û¥¹¥È̾;

mysql> revoke all on mytest.* from okada@'192.168.1.1';
Query OK, 0 rows affected (0.00 sec)

ÅÐÏ¿¥æ¡¼¥¶¤Îºï½ü

mysql> delete from mysql.user where host='192.168.1.1' and user='okada';

or
(mysql> DELETE FROM mysql.user WHERE user='okada';)

mysql> flush privileges;

¥æ¡¼¥¶¤Î¸¢¸Â¤Î³Îǧ

¡ÖGRANT USAGE ON *.* TO 'okada'@'localhost'¡×¤Î¡Ê£±¡Ë¤Î¹Ô¤Ï¤¹¤Ù¤Æ¤Ë¸¢¸Â¤Ê¤·¤ò°ÕÌ£¤¹¤ë¡ÖUSAGE¡×¤Ï¸¢¸Â¤Ê¤·¤Î°ÕÌ£¡£

$ /usr/local/bin/mysql -u root -p
mysql> SHOW GRANTS FOR okada@localhost;
+-----------------------------------------------------------------------------------------------------------------------------+
| Grants for  okada@localhost                                                                                                  |
+-----------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'okada'@'localhost' IDENTIFIED BY PASSWORD '*DD*******44BC****************2D****8C'               |¡¡¡Ê£±¡Ë
| GRANT ALL PRIVILEGES ON `xoops`.* TO 'okada'@'localhost' WITH GRANT OPTION                                                 |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `eccubu_db`.* TO 'okada'@'localhost' WITH GRANT OPTION |
     DB̾(eccubu_db)¤â³Îǧ¤Ç¤­¤ë
+-----------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎºîÀ®

# /usr/local/bin/mysqladmin -u root -p create mytest

ʸ»ú¥³¡¼¥É¤ò»ØÄꤷ¤Æ¥Ç¡¼¥¿¥Ù¡¼¥¹¤ÎºîÀ®

mysql> CREATE DATABASE hoge CHARACTER SET SJIS;

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î°ìÍ÷

# /usr/local/bin/mysqlshow -u root -p
Enter password:
+-----------+
| Databases |
+-----------+
| mysql     |
| mytest    |
| test      |
+-----------+

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Îºï½ü

# /usr/local/bin/mysqladmin -u root -p drop (DB̾)

or

mysql> drop database (DB̾);
¤³¤Î¥³¥Þ¥ó¥É¤À¤±¤Ç¤Ïmysql.db¥Æ¡¼¥Ö¥ë¤Ë»Ä¤Ã¤Æ¤¤¤ë¤è¤¦¤Ê¤Î¤Ç¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò´°Á´¤Ë ºï½ü¤¹¤ë¤Ë¤Ï
mysql> delete from mysql.db where Db='(DB̾)';

¥Æ¡¼¥Ö¥ë¤ÎºîÀ®

t_test.create
create table t_test (
  ID         ¡¡¡¡int8,
  data2          int8,
  data3          varchar(64) character set utf8
);
# /usr/local/bin/mysql -u root -p mytest < t_test.create
Enter password:

mysql> show fields from t_test;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ID    | bigint(20)  | YES  |     | NULL    |       |
| data2 | bigint(20)  | YES  |     | NULL    |       |
| data3 | varchar(64) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

¥Æ¡¼¥Ö¥ë°ìÍ÷

# /usr/local/bin/mysql -u root -p mytest

mysql> SHOW TABLES;
+------------------+
| Tables_in_mytest |
+------------------+
| t_test           |
+------------------+
1 row in set (0.00 sec)

¥Ç¡¼¥¿¤ÎÆþÎÏÅù(postgresql¤ÈƱ¤¸)

mysql> insert into t_test values(1, 1001, 'JE2ISM');
Query OK, 1 row affected (0.00 sec)
mysql> select * from t_test;
+------+-------+--------+
| ID   | data2 | data3  |
+------+-------+--------+
|    1 |  1001 | JE2ISM |
|    2 |  1002 | JF2LYU |
+------+-------+--------+
2 rows in set (0.00 sec)

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×¡¿¥ê¥¹¥È¥¢

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×

# /usr/local/bin/mysqldump -u root -p --default-character-set=latin1 mytest > mytest.out

EUC¤Î¤È¤­¤Ï--default-character-set=ujis¤Ë,UTF8¤Ï utf8¤Ë¤¹¤ë¡£

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥ê¥¹¥È¥¢

Àè¤ËɬÍפʤéGRANT¤Ç¥æ¡¼¥¶Åù¤Ëµö²Ä¤òÍ¿¤¨¤ë¡£
# /usr/local/bin/mysqladmin -u root -p create mytest
# /usr/local/bin/mysql -u root -p mytest < mytest.out

¼¡¤Î¥³¥Þ¥ó¥É¤ò¼Â¹Ô

# /usr/local/bin/mysqladmin flush-privileges

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Îºï½ü

# /usr/local/bin/mysqladmin -u root -p drop mytest
Enter password:
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'mytest' database [y/N] y
Database "mytest" dropped

¥Í¥Ã¥È¥ï¡¼¥¯¾å¤«¤éÀܳµö²Ä¤¹¤ë¤Ë¤Ï

$ /usr/local/bin/mysql -u root -p

¤ÇÀܳ¤·¡¢µö²Ä¤¹¤ë¥æ¡¼¥¶¡¢¥Ñ¥¹¥ï¡¼¥É¡¢¥Í¥Ã¥È¥ï¡¼¥¯(¥Û¥¹¥È¡Ë¤ò»ØÄꤹ¤ë¡£

mysql> GRANT ALL PRIVILEGES ON mytest.* TO okada@'192.168.1.0/255.255.255.0'IDENTIFIED BY '*****' WITH GRANT OPTION;

mysql> flush privileges;

mysql>  select host,user,password from mysql.user;
+----------------------------+------------+------------------------------------ -------+
| host                       | user       | password                                  |
+----------------------------+------------+-------------------------------------------+
| localhost                  | root       | *B*************************************** |
| uso5004.mie-chukyo-u.ac.jp | root       |                                           |  <---Ãí¡Ëroot@uso5004.mie-chukyo-u.ac.jp¤Ç¤Ï¥Ñ¥¹¥ï¡¼¥É¤Ê¤·¤ÇÆþ¤ì¤ë¤Î¤Çɬ¤ººï½ü¤·¤Æ¤ª¤¯É¬¤ººï½ü¤·¤Æ¤ª¤¯
| localhost                  |            |                                           |¡¡<---Ãí¡Ë¤³¤Î¤è¤¦¤Ê¥ì¥³¡¼¥É¤¬¤¢¤ë¤Èuser̾¤¬¤Ê¤ó¤Ç¤â£Ï£Ë¤Ê¤Î¤Çɬ¤ººï½ü¤·¤Æ¤ª¤¯
| localhost                  | moodleuser | *B************************************** |
| 192.168.1.0/255.255.255.0  | okada      | *3************************************** |  <---¤³¤³¤ËÀܳµö²Ä¤¬¼¨¤µ¤ì¤ë
+----------------------------+------------+-------------------------------------------+
6 rows in set (0.00 sec)

¥ê¥â¡¼¥È¤«¤é

°Ê²¼¤Î¥³¥Þ¥ó¥É¤ÇÀܳ

$ /usr/local/bin/mysql -u okada -p mytest -h 192.168.1.1 
Enter password:

MySQL¥µ¡¼¥Ð¡¼¤ÎÁ´ÀßÄê¾ðÊó(ÊÑ¿ô¤ä¥¹¥Æ¡¼¥¿¥¹)¤Îɽ¼¨

mysql> show variables;
mysql> show variables like 'key%';

--------------------------+---------+
| Variable_name           | Value   |

--------------------------+---------+
| key_buffer_size         | 8388600 |
| key_cache_age_threshold |     300 |
| key_cache_block_size    |    1024 |
| key_cache_division_limit|     100 |

--------------------------+---------+
4 rows in set (0.00 sec)
mysql> SHOW STATUS like 'key%';

------------------------+-------+
| Variable_name         | Value |

------------------------+-------+
| Key_blocks_not_flushed|     0 |
| Key_blocks_unused     | 28971 |
| Key_blocks_used       |    24 |
| Key_read_requests     |   231 |
| Key_reads             |    24 |
| Key_write_requests    |     0 |
| Key_writes            |     0 |

------------------------+-------+
7 rows in set (0.00 sec)

**MySQL¥µ¡¼¥Ð¡¼¤ÎÁ´ÀßÄê¾ðÊó(ÊÑ¿ô)¤ÎÀßÄê

/etc/my.cnf¤ËÀßÄꤹ¤ë¤³¤È¤â²Äǽ¤À¤¬¡¢Ä¾ÀÜ¥»¥Ã¥È¤·¤Æ¤â¤è¤¤¡£

mysql> set Global key_buffer_size= 33554432;
Query OK, 0 rows affected (0.01 sec)
SET GLOBAL sort_buffer_size = 10 * 1024 * 1024;
SET SESSION sort_buffer_size = 10 * 1024 * 1024;

¥·¥¹¥Æ¥àÊÑ¿ô¤Ë¤Ï¡¢¥µ¡¼¥Ð¶¦Ä̤ÎÃͤȥ»¥Ã¥·¥ç¥ó(Àܳ)¶¦Ä̤ÎÃͤȤ¢¤ê¡¢ Á°¼Ô¤òÊѹ¹¤¹¤ë¤È¡¢¤½¤Î¸å³«¤«¤ì¤ëÁ´¤Æ¤Î¥»¥Ã¥·¥ç¥ó¤Ë±Æ¶Á¡¢¸å¼Ô¤òÊѹ¹¤¹¤ë¤È¡¢¸½ºß¤Î¥»¥Ã¥·¥ç¥ó¤Ç¤Î¤ß±Æ¶Á

¥Æ¡¼¥Ö¥ë¤Î¥¨¥¯¥¹¥Ý¡¼¥È/¥¤¥ó¥Ý¡¼¥È

¥¨¥¯¥¹¥Ý¡¼¥È

mysql> select * from t_test into outfile "/tmp/t_test.csv" fields terminated by ',' ;

Ãí¡Ëmysql¼Â¹Ô¥æ¡¼¥¶¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ê¤¤¤È½ñ¤­¹þ¤ß¸¢¸Â¤¬¤Ê¤¤¤Î¤Ç¡¢¥¨¥é¡¼¤¹¤ë¤Î¤Ç/tmp¤Ê¤ó¤«¤ò»ØÄꤹ¤ë¡£

¥¤¥ó¥Ý¡¼¥È

mysql> load data infile "/home/okada/mysqltest/t_test.csv" into table t_test fields terminated by ',';

ʸ»ú¥³¡¼¥É¤Ë¤Ä¤¤¤Æ
LOAD DATA INFILE(¥¤¥ó¥Ý¡¼¥È)¤Ïcharacter_set_databaseÊÑ¿ô¤Îcharacter set¤ò»È¤¦¡£
mysql> show variables like 'char%'; ¤Ç³Îǧ

character_set_database   | ujis  <=EUC

DB¤ÎÊѹ¹

root¤Î¾ì¹ç¡¢Â¾¤ÎDB¤ËÊѹ¹¤Ç¤­¤ë

mysql> use authdb
Database changed

´Êñ¤Ê¥Á¥å¡¼¥Ë¥ó¥°

key_buffer_size
¥¤¥ó¥Ç¥Ã¥¯¥¹¥Ö¥í¥Ã¥¯ÍѤ˻ÈÍѤ¹¤ë¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¡£
¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò»È¤¦(¤Ä¤Þ¤ê¤Û¤È¤ó¤ÉÁ´¤Æ¤Î)¥¯¥¨¥ê¤Ï
¤³¤ÎÃͤˤè¤Ã¤Æ¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤¬Â礭¤¯ÊѤï¤ê¤Þ¤¹¡£
¤è¤Ã¤Æ¡¢¤³¤ÎÃͤϲÄǽ¤Ê¸Â¤ê¡Ê¤â¤Á¤í¤ó²ÔÆ°¥·¥¹¥Æ¥à¤ÎµöÍÆÈÏ°ÏÆâ¤Ç¡Ë

Â礭¤¯¤¹¤ë¤³¤È¤¬¿ä¾©¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ŬÀڤʥХåե¡¥µ¥¤¥º¤òµá¤á¤ë¤Ë¤Ï¡¢SHOW STATUS ¥³¥Þ¥ó¥É¤òÍøÍѤ·¤Þ¤¹¡£

¤³¤³¤Çɽ¼¨¤µ¤ì¤¿ Key_read_requests ¤¬¡¢¥­¥ã¥Ã¥·¥å¤«¤é¤Î¥­¡¼¥Ö¥í¥Ã¥¯Æɤ߼è¤êÍ×µá²ó¿ô¤Ç¤¹¡£

Key_reads ¤Ï¡¢¥Ç¥£¥¹¥¯¤«¤é¤Î¥­¡¼¥Ö¥í¥Ã¥¯Æɤ߼è¤êÍ×µá²ó¿ô¤Ç¤¹¡£ ¤Ä¤Þ¤ê¡¢Key_reads / Key_read_requests ¤¬¡Ö¥­¥ã¥Ã¥·¥å¥ß¥¹¥ì¡¼¥È¡×¤Ë¤Ê¤ê¤Þ¤¹¡£

¤³¤ÎÃͤÏ0.01¤ò²¼²ó¤ë¤³¤È¤¬Îɤ¤¤È¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

¤³¤Î¤È¤­¥­¥ã¥Ã¥·¥å¥ß¥¹¥ì¡¼¥È¤Ï1¡ó°Ê²¼¤Ç¤¹¡£

¤³¤ì¤ò¾å²ó¤ë¤è¤¦¤À¤Ã¤¿¤é¡¢ ¥¤¥ó¥Ç¥Ã¥¯¥¹¥Ö¥í¥Ã¥¯¤Î¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤òÂ礭¤¯¤¹¤ë¤³¤È¤ò¸¡Æ¤

my.cnf¤Î¥Ñ¥é¥á¡¼¥¿

¥Ñ¥é¥á¡¼¥¿Ì¾ÀßÄêÆâÍÆ
port = 3306µ¯Æ°¥Ý¡¼¥ÈÈÖ¹æ
key_buffer = 256M¸¡º÷¤Ë»È¤ï¤ì¤ë¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò¥Ð¥Ã¥Õ¥¡¤ËÊݸ¤¹¤ëºÝ¤Î¥á¥â¥ê¥µ¥¤¥º¤òÀßÄꤷ¤Þ¤¹¡£¥á¥â¥ê¤Ë;͵¤¬¤¢¤ë¾ì¹ç¤Ï¤è¤êÂô»³»ØÄê
max_allowed_packet = 1MÆþÎϥǡ¼¥¿ÊÝ»ý¤ÎºÇÂç¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤òÀßÄê¡£²èÁü¤Ê¤É¤ÎÂ礭¤Ê¥Ç¡¼¥¿¤òÁÞÆþ¤¹¤ë¾ì¹ç¤Ï¡¢¤³¤ÎÀ©¸Â¤Ë°ú¤Ã³Ý¤«¤ë²ÄǽÀ­¤¬¤¢¤ë.
table_cache = 256ÉÑÈˤʥ¢¥¯¥»¥¹¤ËÂФ·¤Æ»È¤¦¥Ç¡¼¥¿¥­¥ã¥Ã¥·¥å¤òÀßÄê¡£¤³¤ì¤Ë¤è¤Ã¤Æ¥Ç¥£¥¹¥¯¤ÎI/OÉé²Ù¤ò¸º¤é¤¹¡£
sort_buffer_size = 1MʤÙÂؤ¨¤Î¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤òÀßÄê¡£ÃͤòÂ礭¤¯¤¹¤ë¤³¤È¤Ç ORDER BY ¤ä GROUP BY ¤È¤¤¤Ã¤¿Ê¤ÙÂؤ¨¥¯¥¨¥ê¡¼¤Î®ÅÙ¤ò¾å¤²¤ë¡£
read_buffer_size = 1MÆɤ߹þ¤ß¤Î¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤òÀßÄê¡£ÃͤòÂ礭¤¯¤¹¤ë¤³¤È¤Ç¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò´Þ¤Þ¤Ê¤¤¥¯¥¨¥ê¡¼¤Î¼Â¹Ô®ÅÙ¤ò¾å¤²¤ë¡£
myisam_sort_buffer_size = 64MMyISAM¤Ç»ÈÍѤ¹¤ëʤÙÂؤ¨¤Î¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤òÀßÄê¡£
thread_cache = 8¥¹¥ì¥Ã¥ÉÀ¸À®¤Î¥­¥ã¥Ã¥·¥å¥µ¥¤¥º¤òÀßÄê¡£¥¯¥é¥¤¥¢¥ó¥È¤«¤é¤ÎÀܳ¤ò¼õ¤±¤ë¤È¡¢¥¹¥ì¥Ã¥É¤¬À¸À®¤µ¤ì¡¢¤½¤Î¥¹¥ì¥Ã¥É¤¬¥¯¥é¥¤¥¢¥ó¥È¤ÎSQLʬ¤ò½èÍý¡£¥¯¥é¥¤¥¢¥ó¥È¤ÎÀܳ¤¬Â¿¤¤¾ì¹ç¤ËÍ­¸ú¡£
query_cache_size= 16M¥¯¥¨¥ê¤Î¥­¥ã¥Ã¥·¥å¥µ¥¤¥º¤òÀßÄꡣƱ¤¸¥¯¥¨¥ê¤ò²¿ÅÙ¤â¼Â¹Ô¤¹¤ë¾ì¹ç¤ËÍ­¸ú¡£
thread_concurrency = 8Ʊ»þ¤Ë¼Â¹Ô¤¹¤ë¥¹¥ì¥Ã¥É¿ô¤ò»ØÄê¡£
join_buffer_size = 131072´°Á´·ë¹ç¡Ê¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò»ÈÍѤ·¤Ê¤¤¾ì¹ç¡Ë¤Î¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¤òÀßÄê¡£¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬»ÈÍѤǤ­¤Ê¤¤¾ì¹ç¤ËÍ­¸ú¡£

ODBC

Access¤Ç¥Æ¡¼¥Ö¥ë¥ê¥ó¥¯ºîÀ®»þ¤ÎÃí°Õ

¤â¤·¤â¼ç¥­¡¼¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¥Æ¡¼¥Ö¥ë¤ò¥ê¥ó¥¯¤·¤¿¾ì¹ç¡¢¼¡¤Î¤è¤¦¤Ê
¡Î¸ÇÍ­¥ì¥³¡¼¥É¼±Ê̻ҤÎÁªÂò¡Ï¥À¥¤¥¢¥í¥°¤¬É½¼¨¤µ¤ì¤ë¡£¡Ê­¡¡Ë¤³¤ì¤Ï¡¢¼ç¥­¡¼¤¬
ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢¥Æ¡¼¥Ö¥ë¤Î¹¹¿·¡¦ºï½ü¤Ê¤É¤ËºÝ¤·¤Æ¡¢Àµ¤·¤¯¥Ç¡¼¥¿¤ò
Ʊ´ü¤¹¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¡£¤³¤Î¤è¤¦¤Ê²èÌ̤¬É½¼¨¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
¼ç¥­¡¼¤È¤Ê¤ë¥Õ¥£¡¼¥ë¥É¤òÁªÂò¤¹¤ë¡Ê­¡¡Ë¤«¡¢MySQL¥µ¡¼¥Ð¾å¤Ç¼ç¥­¡¼¤ÎÀßÄꤹ¤ë¡£
ÀßÄꤷ¤Ê¤¤¤È¥Æ¡¼¥Ö¥ë¾å¤Ç¥Ç¡¼¥¿¤ÎÄɲᢽ¤Àµ¤¬¤Ç¤­¤Ê¤¤¡£
ReadOnly¤Ë¤Ê¤ë¤Î¤ÇÃí°Õ¤¹¤ë¡£

MySQLODBC.png

Shell¤«¤é¤¤¤í¤¤¤í

¥Æ¥­¥¹¥ÈTAB·Á¼°¤Ç¤Î¥¨¥¯¥¹¥Ý¡¼¥È

$ /usr/bin/mysql -B --skip-column-names -u ism -p -D eccube_ism -e 'select * 
from dtb_customer;' > dtb_customer.txt
Enter password:

--skip-column-names¤¬¤Ê¤¤¾ì¹ç¤Ïcolumn-names¤â½ÐÎϤ¹¤ë¡£

-h 192.168.30.16 ¤Ç¥Û¥¹¥È»ØÄê

¥Æ¥­¥¹¥ÈTAB·Á¼°¤Ç¤Î¥¤¥ó¥Ý¡¼¥È

$ /usr/bin/mysqlimport --local eccube_ism2 dtb_customer.txt -u ism -p 
Enter password:
eccube_ism2.dtb_customer: Records: 1  Deleted: 0  Skipped: 0  Warnings: 3

»ØÄꤵ¤ì¤¿¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë̾¤Î¼ç¥Õ¥¡¥¤¥ë̾¤Ë°ìÃפ·¤¿¥Æ¡¼¥Ö¥ë¤Ë¥¤¥ó¥Ý¡¼¥È¤µ¤ì¤ë¡£--fields-terminated-by="," ¤È¤·¤Æ ¥Ç¥ê¥ß¥¿¡¼¤ò¡Ö,¡× ¤ò»ØÄê¤Ç¤­¤ë

-h 192.168.30.16 ¤Ç¥Û¥¹¥È»ØÄê --local¤Ï°ÕÌ£¤¬°ã¤¦¤Î¤ÇɬÍ×

$ /usr/bin/mysqlimport --local eccube_ism2 dtb_customer.txt -u ism -p -h  
192.168.30.16
Enter password:
eccube_ism2.dtb_customer: Records: 1  Deleted: 0  Skipped: 0  Warnings: 3

¥ª¥×¥·¥ç¥ó

-l, --lock-tables

¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤ò½èÍý¤¹¤ëÁ°¤Ë¡¢¤¹¤Ù¤Æ¤Î¥Æ¡¼¥Ö¥ë¤Ø¤Î½ñ¤­¹þ¤ß¤ò¥í¥Ã¥¯¤¹¤ë¡£¤³¤ì¤Ë¤è¤ê¡¢¤½¤Î¥µ¡¼¥Ð¾å¤Î¤¹¤Ù¤Æ¤Î¥Æ¡¼¥Ö¥ë¤¬Æ±´ü²½¤µ¤ì¤ë¡£

-L, --local

¥¯¥é¥¤¥¢¥ó¥È¤«¤éÆþÎÏ¥Õ¥¡¥¤¥ë¤òÆɤ߼è¤ë¡£¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢localhost¡Ê¥Ç¥Õ¥©¥ë¥È¥Û¥¹¥È¡Ë¤ËÀܳ¤·¤¿¾ì¹ç¡¢¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤Ï¥µ¡¼¥Ð¤Ë¤¢¤ë¤ÈÁÛÄꤵ¤ì¤ë¡£

-r, --replace

--replace ¥ª¥×¥·¥ç¥ó¤ª¤è¤Ó --ignore ¥ª¥×¥·¥ç¥ó¤Ï¡¢´û¸¥ì¥³¡¼¥É¤ÎÃͤȽÅÊ£¤¹¤ë¥æ¥Ë¡¼¥¯¥­¡¼Ãͤò»ý¤ÄÆþÎϥ쥳¡¼¥É¤Î½èÍý¤òÀ©¸æ¤¹¤ë¡£--replace ¤ò»ØÄꤷ¤¿¾ì¹ç¡¢¿·µ¬¥ì¥³¡¼¥É¤¬Æ±¤¸¥æ¥Ë¡¼¥¯¥­¡¼Ãͤò»ý¤Ä´û¸¥ì¥³¡¼¥É¤ò¾å½ñ¤­¤¹¤ë¡£IGNORE ¤ò»ØÄꤹ¤ë¤È¡¢¥æ¥Ë¡¼¥¯¥­¡¼Ãͤ¬´û¸¤Î¥ì¥³¡¼¥É¤ÎÃͤȽÅÊ£¤¹¤ëÆþÎϥ쥳¡¼¥É¤Ï̵»ë¤µ¤ì¤ë¡£¤É¤Á¤é¤â»ØÄꤷ¤Ê¤¤¾ì¹ç¡¢½ÅÊ£¥­¡¼Ãͤ¬¸¡½Ð¤µ¤ì¤ë¤È¥¨¥é¡¼¤Ë¤Ê¤ê¡¢¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤Î»Ä¤ê¤ÎÉôʬ¤¬Ìµ»ë¤µ¤ì¤ë¡£

defaltʸ»ú¤¬NULL¤Î¾ì¹ç¤Ï¥¨¥¯¥¹¥Ý¡¼¥È¤µ¤ì¤ë¤ÈNULL¤È¤¤¤¦Ê¸»úÎó¤Ë¤Ê¤ë¤¬¡¢¤³¤Î¤Þ¤Þ¥¤¥ó¥Ý¡¼¥È¤¹¤ë¤ÈNULL¤È¤¤¤¦Ê¸»úÎó¤Ë¤Ê¤ë¡£¤è¤Ã¤Æ¡Ö\N¡×¤È¤·¤Æ¥¤¥ó¥Ý¡¼¥È¤¹¤ëɬÍפ¬¤¢¤ë¡£

¥Æ¡¼¥Ö¥ë¤Î¥Ç¡¼¥¿ºï½ü

$ /usr/bin/mysql -B --skip-column-names -u ism -p -D eccube_ism2 -e 'delete 
from dtb_customer;' -h 192.168.30.16
Enter password:

¥Ñ¥¹¥ï¡¼¥ÉÆþ¤ì¤ë¤Ë¤Ï

--password=****¤È¤¹¤ì¤ÐÎɤ¤

$ /usr/bin/mysqlimport --local eccube_ism2 dtb_customer.txt -u ism --pass
word=**** -h 192.168.30.16
eccube_ism2.dtb_customer: Records: 1  Deleted: 0  Skipped: 0  Warnings: 3

EC CUBE¤ÎÊ£¿ô¤ÎŹ¤Î¥æ¡¼¥¶¤òñ°ì´ÉÍý

DB¤«¤é¥Æ¡¼¥Ö¥ë¤ò¥¨¥¯¥¹¥Ý¡¼¥È¤·¤Æ¤½¤ì¤òÊ̥ơ¼¥Ö¥ë¤Ë¥¤¥ó¥Ý¡¼¥È¡£Æ±¤¸¥æ¥Ë¡¼¥¯¥­¡¼¤¬ ¤¢¤ë»þ¤Ï¾å½ñ¤­¤¹¤ë¡£

tbsync.php

<?php

       $cmd = "/usr/bin/mysql -B --skip-column-names -u ism --password=*** -D eccube_ism -e 'select * from dtb_customer;' -h 192.168.30.16";
       exec($cmd, $output);
       $fp=fopen("/home/okada/temp/dtb_customer.txt","w");

       foreach ($output as $a){
               fputs($fp,$a."\n");
       }
       fclose($fp);

       $cmd ="/usr/bin/mysqlimport --local eccube_ism2 /home/okada/temp/dtb_customer.txt-u ism --password=*** -r -h 192.168.30.16";
       exec($cmd);
?>

html/entry/complete.php¤Èhtml/mypage¤Îrefusal_complete.php¤Èchange_complete.phpºÇ¸å¤Î¹Ô¤Ë

require_once("/home/okada/temp/tbsync.php");

¤òÄɲÃ

»²¹Í

MySQL¥¯¥¤¥Ã¥¯¡¦¥ê¥Õ¥¡¥ì¥ó¥¹

MySQL¤ÎÊÑ¿ô


¸µ¥Ú¡¼¥¸

¥È¥Ã¥×   ¿·µ¬ °ìÍ÷ ¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS