{"id":1445,"date":"2025-02-22T13:03:45","date_gmt":"2025-02-22T04:03:45","guid":{"rendered":"https:\/\/daba-no-heya.com\/?p=1445"},"modified":"2025-02-22T18:29:06","modified_gmt":"2025-02-22T09:29:06","slug":"post-1445","status":"publish","type":"post","link":"https:\/\/daba-no-heya.com\/?p=1445","title":{"rendered":"MySQL\u306eTINYINT(1)\u306b\u306f0\u30681\u4ee5\u5916\u3082\u5165\u308a\u307e\u3059\uff01"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/daba-no-heya.com\/?p=1445\/#%E6%A6%82%E8%A6%81\" >\u6982\u8981<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/daba-no-heya.com\/?p=1445\/#%E5%AE%9F%E9%9A%9B%E3%81%AB%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B\" >\u5b9f\u969b\u306b\u8a66\u3057\u3066\u307f\u308b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/daba-no-heya.com\/?p=1445\/#%E8%80%83%E5%AF%9F\" >\u8003\u5bdf<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A6%82%E8%A6%81\"><\/span>\u6982\u8981<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><code>TINYINT(1)<\/code>\u306e<code>(1)<\/code>\u306e\u90e8\u5206\u306f\u8868\u793a\u5e45(display width)\u306e\u8a2d\u5b9a\u3067\u3042\u3063\u3066\u3001\u683c\u7d0d\u3067\u304d\u308b\u5024\u306e\u5236\u9650\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<br>\u3053\u308c\u306f\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3082\u8a18\u8f09\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/numeric-type-syntax.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/numeric-type-syntax.html<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/numeric-type-attributes.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/numeric-type-attributes.html<\/a><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Display width is unrelated to the range of values a type can store, as described in&nbsp;<a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/numeric-type-attributes.html\">Section&nbsp;13.1.6, \u201cNumeric Type Attributes\u201d<\/a>.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The display width does&nbsp;<em>not<\/em>&nbsp;constrain the range of values that can be stored in the column.<\/p>\n<\/blockquote>\n\n\n\n<p>\u305d\u3057\u3066\u3053\u306e\u6a5f\u80fd\u306fMySQL 8.0.17\u6642\u70b9\u3067\u975e\u63a8\u5968\u306b\u306a\u3063\u305f\u65e8\u306e\u8a18\u8f09\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>As of MySQL 8.0.17, the display width attribute is deprecated for integer data types; you should expect support for it to be removed in a future version of MySQL.<\/p>\n<\/blockquote>\n\n\n\n<p>\u3057\u305f\u304c\u3063\u3066\u3001<code>TINYINT(1)<\/code>\u306b\u683c\u7d0d\u3067\u304d\u308b\u5024\u306e\u7bc4\u56f2\u306f<code>TINYINT<\/code>\u3068\u540c\u3058\u3067\u3001-128\u304b\u3089127\u307e\u3067\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/integer-types.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/integer-types.html<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%9A%9B%E3%81%AB%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B\"><\/span>\u5b9f\u969b\u306b\u8a66\u3057\u3066\u307f\u308b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Docker\u3067MySQL\u306e\u30b3\u30f3\u30c6\u30ca\u3092\u8d77\u52d5\u3057\u3066\u691c\u8a3c\u3057\u3066\u307f\u307e\u3059\u3002<br><code>.env<\/code>\u30d5\u30a1\u30a4\u30eb\u306b\u306froot\u30e6\u30fc\u30b6\u30fc\u306e\u30d1\u30b9\u30ef\u30fc\u30c9(<code>MYSQL_ROOT_PASSWORD<\/code>)\u3092\u8a18\u8f09\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ docker run --env-file .env --name mysql_test -d mysql:8.0.41<\/code><\/pre>\n\n\n\n<p>\u30b3\u30f3\u30c6\u30ca\u306e\u4e2d\u306b\u5165\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ docker exec -it mysql_test bash<\/code><\/pre>\n\n\n\n<p>\u30b3\u30f3\u30c6\u30ca\u306b\u5165\u308b\u3068mysql\u30b3\u30de\u30f3\u30c9\u304c\u4f7f\u3048\u308b\u306e\u3067\u3001MySQL\u306b\u63a5\u7d9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash-5.1# mysql -u root -p<\/code><\/pre>\n\n\n\n<p>\u9069\u5f53\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u691c\u8a3c\u7528\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; CREATE DATABASE example;\nQuery OK, 1 row affected (0.00 sec)\n\nmysql&gt; USE example;\nDatabase changed\nmysql&gt; CREATE TABLE example (id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,v1 TINYINT(1),v2 TINYINT);\nQuery OK, 0 rows affected, 1 warning (0.02 sec)<\/code><\/pre>\n\n\n\n<p>\u9069\u5f53\u306a\u5024\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; INSERT INTO example (v1,v2) VALUES (100,100);\nQuery OK, 1 row affected (0.00 sec)\n\nmysql&gt; INSERT INTO example (v1,v2) VALUES (-100,-100);\nQuery OK, 1 row affected (0.01 sec)<\/code><\/pre>\n\n\n\n<p>\u8ffd\u52a0\u3057\u305f\u5024\u3092\u8868\u793a\u3057\u3066\u307f\u308b\u3068\u3001<code>TINYINT(1)<\/code>\u3092\u6307\u5b9a\u3057\u305f<code>v1<\/code>\u306b\u3082100\u3084-100\u3068\u3044\u3063\u305f\u5024\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; SELECT * FROM example;\n+----+------+------+\n| id | v1   | v2   |\n+----+------+------+\n|  1 |  100 |  100 |\n|  2 | -100 | -100 |\n+----+------+------+\n2 rows in set (0.00 sec)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%80%83%E5%AF%9F\"><\/span>\u8003\u5bdf<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>&#8220;mysql tinyint(1)&#8221;\u3068\u304b\u3067Google\u691c\u7d22\u3057\u3066\u307f\u308b\u3068\u3001<code>TINYINT(1)<\/code>\u306f1 bit\u306e\u5024\u3060\u304b\u30890 (false)\u304b1 (true)\u3057\u304b\u5165\u3089\u306a\u3044\u3001\u3068\u3044\u3063\u305f\u8aac\u660e\u3092\u6bd4\u8f03\u7684\u591a\u304f\u898b\u304b\u3051\u307e\u3059\u3002<br>\u3082\u3057\u304b\u3057\u3066MySQL\u306e\u53e4\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3060\u3068\u305d\u3046\u3044\u3046\u52d5\u4f5c\u3060\u3063\u305f\u306e\u304b\u3001\u3068\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u30012012\u5e74\u306eStack Overflow\u306e\u8cea\u554f\u3067\u3082<code>(M)<\/code>\u306f\u8868\u793a\u5e45\u3060\u304b\u3089\u5024\u306e\u7bc4\u56f2\u3068\u306f\u95a2\u4fc2\u306a\u3044\u3001\u3068\u3044\u3046\u56de\u7b54\u304c\u3042\u308b\u306e\u3067\u3001\u305d\u3046\u3044\u3046\u308f\u3051\u3067\u3082\u306a\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/12839927\/mysql-tinyint-2-vs-tinyint1-what-is-the-difference\">https:\/\/stackoverflow.com\/questions\/12839927\/mysql-tinyint-2-vs-tinyint1-what-is-the-difference<\/a><\/li>\n<\/ul>\n\n\n\n<p>MySQL\u306e<code>BOOLEAN<\/code>\u3068\u4e00\u822c\u7684\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u30d6\u30fc\u30eb\u5024\u304c\u6df7\u540c\u3055\u308c\u305f\u7d50\u679c\u306a\u306e\u304b\u306a\u3001\u3068\u3082\u601d\u3044\u307e\u3059\u3002<br>MySQL\u306e<code>BOOLEAN<\/code>\u306f<code>TINYINT(1)<\/code>\u3068\u3057\u3066\u6271\u308f\u308c\u308b\u305f\u3081\u3001\u30d6\u30fc\u30eb\u5024\u306b\u306ffalse\u304btrue\u3057\u304b\u5165\u3089\u306a\u3044\u3001\u3064\u307e\u308a<code>TINYINT(1)<\/code>\u306f0 (false)\u304b1 (true)\u3057\u304b\u5165\u3089\u306a\u3044\u578b\u3067\u3042\u308b\u3001\u3068\u3044\u3046\u63a8\u6e2c\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u3042\u3001\u5b9f\u969b\u306e\u3068\u3053\u308d\u3069\u3046\u3044\u3046\u7d4c\u7def\u3067\u5e83\u307e\u3063\u305f\u8aac\u660e\u306a\u306e\u304b\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u304c&#8230;\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 TINYINT(1)\u306e(1)\u306e\u90e8\u5206\u306f\u8868\u793a\u5e45(display width)\u306e\u8a2d\u5b9a\u3067\u3042\u3063\u3066\u3001\u683c\u7d0d\u3067\u304d\u308b\u5024\u306e\u5236\u9650\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u308c\u306f\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3082\u8a18\u8f09\u304c\u3042\u308a\u307e\u3059\u3002 Display width is unrelat [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,8],"tags":[],"class_list":["post-1445","post","type-post","status-publish","format-standard","hentry","category-mysql","category-8"],"_links":{"self":[{"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=\/wp\/v2\/posts\/1445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1445"}],"version-history":[{"count":4,"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=\/wp\/v2\/posts\/1445\/revisions"}],"predecessor-version":[{"id":1450,"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=\/wp\/v2\/posts\/1445\/revisions\/1450"}],"wp:attachment":[{"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daba-no-heya.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}