db4free.net 㧠MySQL 8.0
ããã«ã¡ã¯ãã¿ãªãã MySQL ãã¥ã¼ãã³ã°ãã¦ã¾ããï¼ nobuh ã§ãã
ä»å㯠MySQL 8.0 DMRï¼éçºãã¤ã«ã¹ãã¼ã³çï¼ããªãªã¼ã¹ãããã¨ãè¨å¿µãã¾ãã¦ãæ©é 8.0 ã触ã£ã¦ã¿ããã¨ããã話ã§ãã
DMRçã® MySQL ãå
¥ããæ¹æ³ã¯ããããããã¾ããVirtualBox ã«ç«ã¦ããµã¼ãã¼ã« yum/apt ã§å
¥ããããVagrant, Docker ã使ã£ãããªã©ãã¿ãªãããæ¥å¸¸çã«è¡ããã¦ããã¨æãã¾ããä»åã¯ã¡ãã£ã¨è¶£åãå¤ãã¾ã㦠db4free.net ã¨ãããã¹ãåãã«ææ°ã® MySQL ãç¡æã§ãã¹ãã£ã³ã°ãã¦ãããµã¼ãã¹ãããã¾ãã®ã§ããã¡ãã使ã£ã¦ã¿ã¾ããã
ã¾ãã¯ç»é²
db4free.net ã§ããã2ã¤ãµã¼ãã¹ãããã¾ãã
- db4free.net – GAç MySQL 5.7 ã®ææ°ããã¹ãã£ã³ã°
- mysql8.db4free.net – åºãã°ããã® 8.0 DMR ããã¹ãã£ã³ã°
å®å®ææ°çã® MySQL 5.7 ãã¾ã ã¾ã å¦ã¶ã¹ããã®ãä¸æ¯ããã¾ãããä»åã¯æ¬ã® 8.0 ã使ãããã®ã§ mysql8.db4free.net ã使ãã¾ããããããã¼ã¸ã«ãç¡æã§ã¢ã«ã¦ã³ãä½æãã®ãªã³ã¯ãããã¾ãã®ã§ã¯ãªãã¯ãã¾ãã
ç»é²ãã¼ã¸ãã·ã³ãã«ã§ãã
å¿ è¦ãªãã®ã¯
- MySQLãã¼ã¿ã¼ãã¼ã¹å
- MySQLã¦ã¼ã¶ã¼å
- MySQLãã¹ã¯ã¼ã
- ç»é²Eã¡ã¼ã«ã¢ãã¬ã¹
ã ãã§ããåæã«ãâããã¤ããããããµã¤ã³ã¢ãããããã¿ã³ãæ¼ãã°å®äºï¼
MySQL ã®ãµã¼ãã¹ãªã®ã§ MySQLã®ã¦ã¼ã¶ã¼ï¼ãã¹ã¯ã¼ãããã®ã¾ã¾ãã®ãµã¼ãã¹ã®ã¢ã«ã¦ã³ãã«ãªã£ã¦ãã¾ããç´çã§ç¡é§ãç¡ãã§ããï¼
ãããdb4free.netã«ãã¼ã¿ãã¼ã¹ãä½æããã¾ãããã¡ã¼ã«ãæ¥ã¾ãã®ã§ããã®ã¡ã¼ã«æä¸ã®ãªã³ã¯ãã¯ãªãã¯ãã¦ç»é²ãæå¹ã«ãã¾ãã
ãã¬ã¼ã³ãªã¡ã¼ã«ã§ãªã³ã¯ãå¤ãæå¤ã«è¦ã¤ããã®ãé£ããã®ã§æç²ãã¾ãããç®ã ãï½ç¿»è¨³ãæä¼ã£ã¦ï½ããã¾ã§è¡ãã¨è¡ãéãã§ãï¼
ãã£ãã phpMyAdmin ã使ã£ã¦ã¿ã
ããããã¼ã¸ã®å·¦ãµã¤ãä¸ã« phpMyAdmin ã¸ã®ãã°ã¤ã³ç»é¢ãããã¾ãã®ã§ããããããã°ã¤ã³ãã¾ãã
ãã°ã¤ã³ããã¨ãããã¯ãã¤ãã® phpMyAdmin ã®ä¸çãåºãã£ã¦ãã¾ãï½ãæä½å¯è½ãªãã¼ã¿ã¼ãã¼ã¹ã¯èªåã®ä½æãããã¼ã¿ãã¼ã¹ã ãã§ãããç¶æ
ï¼ã¢ãã¿ãã«ããã°ã©ãæ©è½ãªã©ãé常éãå©ç¨å¯è½ã§ãã
MySQL 8.0 ã®ä¸çã¸
phpMyAdmin 使ããã ãã§æºè¶³æä¸æ¯ã§ãããããã§æ¢ã¾ããã«æ¬é¡ã® MySQL 8.0 ã«ææ¦ãã¾ããããã¾ã㯠mysql ã¯ã©ã¤ã¢ã³ãã§ã¢ã¯ã»ã¹ãã¾ããã¨ããããæå ã®ãã·ã³ã MySQL 5.7 ã®ã¯ã©ã¤ã¢ã³ããå ¥ã£ã¦ãã¾ããã®ã§ããã使ãã¾ãã
YOU ~]$ mysql --version mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrapper
æ¥ç¶å 㯠db4free.net ã® port 3307 ã«ãªãã¾ãã®ã§ mysql ã¯ã©ã¤ã¢ã³ãããç´æ¥ã¢ã¯ã»ã¹ãã¦ã¿ã㨅 8.0.0-dmr ã®æåãï¼
YOU ~]$ mysql -h db4free.net -P 3307 -uYOURNAME Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 45022 Server version: 8.0.0-dmr MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>
æ©éä½ã MySQL 8 ã£ã½ãæ©è½ã使ã£ã¦ã¿ã¾ãããã
ä¸å¯è¦ã¤ã³ããã¯ã¹ã使ã£ã¦ã¿ã
MySQL 8.0 ãããã¼ã¿ã¨ãã¦ã¯ä¿åããã¦åå¨ãã¦ãããã®ã®ãSELECT ã®ããã®å®è¡è¨ç»ã§ã¯ãã£ããã«é¸ã°ããªãã¨ããä¸å¯è¦ã¤ã³ããã¯ã¹ã®æ©è½ã追å ããã¾ãããã¤ã³ããã¯ã¹ãåé¤ããã¨ãã«ãä¸åº¦ä¸å¯è¦ã¤ã³ããã¯ã¹ã®ç¶æ
ã«ç½®ããã¨ã§ãã¤ã³ããã¯ã¹ãç¡ããªã£ã¦ SELECT æ§è½ãã©ããªããååã«ç¢ºèªãããã¨ãã§ãã¾ããããã¦æå¾ã«ããOKã¨ãªã£ã¦ããå®éã«ã¤ã³ããã¯ã¹ãåé¤ãããã¨ãåºæ¥ã¾ãã
ã¤ã³ããã¯ã¹åé¤å¾ã«ãã£ã±ãä½æãç´ãã¨ãªãã¨ãã·ã¹ãã ã«ä¸ããè² è·ã¯å¤§ãããªãã¾ãããä¸å¯è¦ã¤ã³ããã¯ã¹ã¸ã®å¤æ´ãããã¯ãããå
ã«æ»ãã®ãã¡ã¿ãã¼ã¿ã®å¤æ´ã®ã¿ã§è»½ããã§ããããå®å
¨ã«ã¤ã³ããã¯ã¹ãåé¤åºæ¥ãããã«ãªãã¾ãã®ã§ãä¸å¯è¦ã¤ã³ããã¯ã¹ã¯æå¾
ã§ããããªæ©è½ã§ããããã§ã¯ãã¹ããã¦ã¿ã¾ãããã
ã¾ã㯠Auto Inc ã®ãã©ã¤ããªãã¼ã¨æåã«ã©ã ã追å ã¤ã³ããã¯ã¹ã¯ä¸ã¤ã ãã®ãã¼ãã«ãä½æãã¾ãã
mysql> CREATE TABLE t (p int auto_increment primary key, c char(80), key k (c));
1è¡ç®ã空ã§ã¤ã³ãµã¼ã
mysql> insert into t () values ();
2è¡ç®ä»¥é㯠insert … select ã使ãã¾ãã
mysql> insert into t (c) select c from t;
ãã¨ã¯âãã¼ã§æ»ã£ã¦ãã®ã¯ã¨ãªãç¹°ãè¿ãå©ãã°ã2 ã® n ä¹ã®ã¹ãã¼ãã§è¡æ°ãå¢ãã¾ããã¨ãããã1024è¡ç¨æãã¾ããã
mysql> select count(*) from t; +----------+ | count(*) | +----------+ | 1024 | +----------+
ãã®ã¾ã¾ã 㨠c ã®ã«ã©ã ã¯å ¨é¨ NULL ã®ã¾ã¾ã§ãã¼ã¿ããããªãã®ã§å å·¥ãã¾ããè±æ°4æåãã©ã³ãã ã«æ±ºå®ããã«ã¯ RAND 㨠MD5 ã使ã£ã¦ãã®ããã«æ¸ããã¨ãã§ãã¾ãã
mysql> SELECT SUBSTRING(MD5(RAND()), 1, 4); +------------------------------+ | SUBSTRING(MD5(RAND()), 1, 4) | +------------------------------+ | 54d4 | +------------------------------+
ãã®æ¹æ³ã使ã£ã¦å ¨è¡ãã©ã³ãã ã«æ´æ°ãã¾ãã
mysql> update t set c = SUBSTRING(MD5(RAND()), 1, 4); Query OK, 1024 rows affected (0.90 sec) Rows matched: 1024 Changed: 1024 Warnings: 0
çãä¸ãããã®3è¡è¦ã¦ã¿ã¾ã
mysql> select * from t limit 500,3; +------+------+ | p | c | +------+------+ | 1088 | 7f2b | | 1020 | 7f4f | | 70 | 7f74 | +------+------+
ãããã®å¤ã®ä¸¦ã³ã¯ããããã ç¡æ¡ä»¶ select ã§ãã©ã¤ããªãã¼ã§ã¯ãªãã¤ã³ããã¯ã¹ã使ããã¦ãããã¨ã«ããé©ãã¤ã¤ããã¨ãããããµã³ãã«ã¨ã㦠c = ‘7f4f’ ãé¸ã³ã¾ãããããã¦å¿µã«ã¯å¿µãå ¥ãééããªãã¤ã³ããã¯ã¹ã使ãããããã« FORCE ãã¤ãã¦ãæ¤ç´¢ããã¨ãã® explain ãè¦ãã¨ããã
mysql> explain select * from t force index (k) where c = '7f4f'; +----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+-------------+ | 1 | SIMPLE | t | NULL | ref | k | k | 321 | const | 1 | 100.00 | Using index | +----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+-------------+ 1 row in set, 1 warning (0.28 sec)
ãããã«ã¤ã³ããã¯ã¹ã使ããã¦1è¡ãã³ãã¤ã³ãã« SELECT ãã¾ãããããã¦ããã®ç¶æ ããã¤ã³ããã¯ã¹ k ãä¸å¯è¦åãã¾ãã
mysql> ALTER TABLE t ALTER INDEX k INVISIBLE; Query OK, 0 rows affected (0.40 sec) Records: 0 Duplicates: 0 Warnings: 0
ãã®ç¶æ ã§å度åãã¯ã¨ãªã® explain ãè¦ãã¨ããã
mysql> explain select * from t force index (k) where c = '7f4f'; +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+ | 1 | SIMPLE | t | NULL | ALL | NULL | NULL | NULL | NULL | 1024 | 10.00 | Using where | +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
ä»ã¯ã¤ã³ããã¯ã¹ãç¡ãã«ã©ã c ãæ¡ä»¶ã« select ãã¦ãã¾ãã®ã§ãæ³å®éããã«ãã¼ãã«ã¹ãã£ã³ã«ãªãã¾ããã
ä¸å¯è¦åãããã¤ã³ããã¯ã¹ãç¡çãã FORCE æå®ãã¦ãã¦ãã¨ã©ã¼ã«ã¯ãªãããpossible_keys ã«è¼ã£ã¦æ¥ã¦ããªãã¦åã«é¸ã°ãã¦ããªãã ãã®æåã«ãªããã¨ããããã¾ãã
ãã®ç¶æ
㧠show index ãã¦ã¿ãã¨ã¤ã³ããã¯ã¹ã¯ã¡ããã¨åå¨ãã¦ãã¦ããã ã Visible ã«ã©ã ã NO ã«ãªã£ã¦ãããã¨ããããã¾ãã
mysql> mysql> show index from t; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | t | 0 | PRIMARY | 1 | p | A | NULL | NULL | NULL | | BTREE | | | YES | | t | 1 | k | 1 | c | A | NULL | NULL | NULL | YES | BTREE | | | NO | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
information_schema ã®çµ±è¨æ å ±ãã¼ãã«ã«ã¯ is_visible ã¨ããã«ã©ã ãããã¾ãã®ã§ãªã¹ãã¢ãããã¦ã¿ã¾ã
mysql> SELECT * FROM information_schema.statistics WHERE is_visible='NO'\G *************************** 1. row *************************** TABLE_CATALOG: def TABLE_SCHEMA: ###YOU### TABLE_NAME: t NON_UNIQUE: 1 INDEX_SCHEMA: ###YOU### INDEX_NAME: k SEQ_IN_INDEX: 1 COLUMN_NAME: c COLLATION: A CARDINALITY: NULL SUB_PART: NULL PACKED: NULL NULLABLE: YES INDEX_TYPE: BTREE COMMENT: INDEX_COMMENT: IS_VISIBLE: NO
ããã¦æ»ãã¨ã㯠VISIBLE ã§ãã
mysql> ALTER TABLE t ALTER INDEX k VISIBLE; Query OK, 0 rows affected (0.51 sec) Records: 0 Duplicates: 0 Warnings: 0
ããã ãã§ã¤ã³ããã¯ã¹ã復活ã§ãï¼
ãããã§ããã§ãããããdb4free.net ã使ããã¨ã§ãMySQL 8.0 ããæ軽ã«ä½é¨ãããã¨ãåºæ¥ã¾ãããçæ§ããã®æ©ä¼ã«ãã² db4free.net ã MySQL 8.0 ãä½é¨ãã¦ã¿ã¦ãã ããï¼
å¼ç¤¾ã§ã¯ MySQL ã大好ããªã¨ã³ã¸ãã¢ãåéãã¦ãã¾ãã®ã§ããèå³ããæ¹ã®ãå¿åããå¾
ã¡ãã¦ãã¾ãï¼ï¼ãâæ¡ç¨æ
å ±