Skip to content

Instantly share code, notes, and snippets.

@agungsijawir
Created August 21, 2018 04:15
Show Gist options
  • Save agungsijawir/2d86c781e87588b9ec22a09203d47728 to your computer and use it in GitHub Desktop.
Save agungsijawir/2d86c781e87588b9ec22a09203d47728 to your computer and use it in GitHub Desktop.
# mysql --version
mysql Ver 15.1 Distrib 10.1.35-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
# mysql -uroot -p
MariaDB [(none)]> create schema `test_ai`;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> use `test_ai`;
Database changed
MariaDB [test_ai]> DROP TABLE IF EXISTS `my_table`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
MariaDB [test_ai]> CREATE TABLE `my_table` (`id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL, `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.02 sec)
MariaDB [test_ai]> INSERT INTO `my_table` (`name`, `created_at`) VALUES ('data 1', '0000-00-00 00:00:00');
MariaDB [test_ai]> INSERT INTO `my_table` (`name`, `created_at`) VALUES ('data 2', '0000-00-00 00:00:00');
MariaDB [test_ai]> INSERT INTO `my_table` (`name`, `created_at`) VALUES ('data 3', '0000-00-00 00:00:00');
MariaDB [test_ai]> INSERT INTO `my_table` (`name`, `created_at`) VALUES ('data 4', '0000-00-00 00:00:00');
MariaDB [test_ai]> INSERT INTO `my_table` (`name`, `created_at`) VALUES ('data 5', '0000-00-00 00:00:00');
MariaDB [test_ai]> INSERT INTO `my_table` (`name`, `created_at`) VALUES ('data 6', '0000-00-00 00:00:00');
MariaDB [test_ai]> INSERT INTO `my_table` (`name`, `created_at`) VALUES ('data 1', '0000-00-00 00:00:00');
Query OK, 1 row affected (0.00 sec)
MariaDB [test_ai]> SHOW TABLE STATUS FROM `test_ai` WHERE `name` LIKE '%my_table%' ;
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| my_table | InnoDB | 10 | Compact | 6 | 2730 | 16384 | 0 | 0 | 0 | 7 | 2018-08-21 10:27:03 | NULL | NULL | utf8mb4_general_ci | NULL | | |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.01 sec)
MariaDB [test_ai]> SELECT MAX(id) from my_table;
+---------+
| MAX(id) |
+---------+
| 6 |
+---------+
1 row in set (0.01 sec)
MariaDB [test_ai]> DELETE FROM my_table WHERE id IN (1,2,3,4,5,6);
Query OK, 6 rows affected (0.01 sec)
MariaDB [test_ai]> SHOW TABLE STATUS FROM `test_ai` WHERE `name` LIKE '%my_table%' ;
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| my_table | InnoDB | 10 | Compact | 6 | 2730 | 16384 | 0 | 0 | 0 | 7 | 2018-08-21 10:27:03 | NULL | NULL | utf8mb4_general_ci | NULL | | |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.01 sec)
MariaDB [test_ai]> exit
Bye
--------------
# sudo systemctl restart mariadb
# mysql -uroot -p
MariaDB [(none)]> SHOW TABLE STATUS FROM `test_ai` WHERE `name` LIKE '%my_table%' ;
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| my_table | InnoDB | 10 | Compact | 1 | 16384 | 16384 | 0 | 0 | 0 | 1 | 2018-08-21 11:08:44 | NULL | NULL | utf8mb4_general_ci | NULL | | |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment