1. 程式人生 > >mysql8基礎 table 在指定資料庫建立表

mysql8基礎 table 在指定資料庫建立表

資料,資料,命根就在資料 ! 操作資料庫時,一定要謹慎小心。師萬物 的程式碼看看就好,要有自己的判斷。遇到抉擇,要不恥上下問。

example

stu@Ubuntu:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 8.0.12 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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> use db_chinese_medicine; Reading table information for
completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> create table `t_fruit`( -> `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主鍵,自增長', -> `name` varchar(15) NOT NULL COMMENT '名稱,唯一', -> `count` int
(11) NOT NULL COMMENT '數量', -> `price` decimal(6,3) NOT NULL COMMENT '每兩價格', -> `is_sales` tinyint(1) not null default 1 comment'銷售狀態,1為正在銷售,0為停售', -> `note` varchar(255) default '無' comment'備註,預設:無', -> `gmt_create` datetime NOT NULL COMMENT '建立時間', -> `gmt_modified` datetime NOT NULL COMMENT '最後修改時間', -> PRIMARY KEY (`id`), -> UNIQUE KEY `name` (`name`) -> ) -> ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='果部藥物表'; Query OK, 0 rows affected (0.13 sec) mysql> desc t_fruit; +--------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | name | varchar(15) | NO | UNI | NULL | | | count | int(11) | NO | | NULL | | | price | decimal(6,3) | NO | | NULL | | | is_sales | tinyint(1) | NO | | 1 | | | note | varchar(255) | YES | || | | gmt_create | datetime | NO | | NULL | | | gmt_modified | datetime | NO | | NULL | | +--------------+------------------+------+-----+---------+----------------+ 8 rows in set (0.00 sec) mysql> exit Bye stu@Ubuntu:~$

reference

resource

MySQL是一個關係型資料庫管理系統,目前是開源的(2018-10)。
許可權明確,引擎與字符集等選擇恰當,命名規範。
MariaDB,Redis,MongoDB,PostgreSQL,Hive,HBase等,多作了解,拓寬心量。
Workbench,phpMyAdmin,Navicat等圖形化管理工具,需要細心使用,豫兮若冬涉川。