mysql终端基本操作与数据类型

mysql终端基本操作与数据类型笔记 ,mysql框架 : 服务器——数据库——表——字段 。
我使用的mysql80, 直接打开mysql8.0 Command Line Client, 输入密码即可登录服务器

Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.11 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| school             |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
如何新建数据库
mysql> create database test;  # 新建名为 test 的数据库
Query OK, 1 row affected (0.04 sec)
如何删除数据库
mysql> drop database test;  #  删除名为 test 的数据库
Query OK, 0 rows affected (0.03 sec)
如何选择数据库
mysql> use school;  # 选择名为school 的数据库
Database changed
如何查看当前数据库有哪些表
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| courses          |
| scores           |
| students         |
| teachers         |
+------------------+
4 rows in set (0.00 sec)
如何查看表的描述信息
mysql> desc students;   # 或者describe students;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| sid       | int(11)     | NO   | PRI | NULL    |       |
| sname     | varchar(10) | NO   |     | NULL    |       |
| sgender   | varchar(10) | NO   |     | NULL    |       |
| sbrithday | date        | NO   |     | NULL    |       |
| sclass    | int(11)     | NO   |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
如何查看数据具体信息
mysql>  select * from students;
+-----+------------+---------+------------+--------+
| sid | sname      | sgender | sbrithday  | sclass |
+-----+------------+---------+------------+--------+
|   1 | zhangsan   | nan     | 1995-10-10 |    601 |
|   2 | lisi       | nv      | 1995-10-10 |    601 |
|   3 | wangermazi | nan     | 1995-04-10 |    602 |
|   4 | huangwu    | nan     | 1995-10-10 |    602 |
|   5 | zhaoliu    | nv      | 1995-05-10 |    603 |
|   6 | zhaoliu    | nv      | 1995-03-10 |    603 |
+-----+------------+---------+------------+--------+
6 rows in set (0.00 sec)
如何退出数据库服务器
exit;  # 或者 quit;
mysql 常见数据类型

数据类型一共有四种,整型 , 浮点型, 字符串, 日期 。每个种类有不同长度或者格式类型。

整型
类型大小范围 (有符号)无符号适用
TINYINT1 byte(-128,127)(0,255)小整数值
SMALLINT2 bytes(-32 768,32 767)(0,65 535)大整数值
MEDIUMINT3 bytes(-8 388 608,8 388 607)(0,16 777 215)大整数值
INT4 bytes(-2 147 483 648,2 147 483 647)(0,4 294 967 295)较大整数值
BIGINT8 bytes(-9,223,372,036,854,775,808,9 223 372 036 854 775 807)(0,18 446 744 073 709 551 615)极大整数值
浮点型
类型大小范围 (有符号)无符号适用
FLOAT4 bytes(-3.402 823 466 E+38,-1.175 494 351 E-38),0,(1.175 494 351 E-38,3.402 823 466 351 E+38)0,(1.175 494 351 E-38,3.402 823 466 E+38)单精度浮点数值
DOUBLE8 bytes(-1.797 693 134 862 315 7 E+308,-2.225 073 858 507 201 4 E-308),0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308)0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308)双精度
浮点数值
DECIMAL对DECIMAL(M,D) ,如果M>D,为M+2否则为D+2依赖于M和D的值依赖于M和D的值小数
字符串
类型大小适用
CHAR0-255 bytes定长字符串
VARCHAR0-65535 bytes变长字符串
TINYBLOB0-255 bytes不超过 255 个字符的二进制字符串
TINYTEXT0-255 bytes短文本字符串
BLOB0-65 535 bytes二进制形式的长文本数据
TEXT0-65 535 bytes长文本数据
MEDIUMBLOB0-16 777 215 bytes二进制形式的中等长度文本数据
MEDIUMTEXT0-16 777 215 bytes中等长度文本数据
LONGBLOB0-4 294 967 295 bytes二进制形式的极大文本数据
LONGTEXT0-4 294 967 295 bytes极大文本数据
日期与时间类型
类型大小范围格式适用
DATE3 byte1000-01-01/9999-12-31YYYY-MM-DD日期值
TIME3 bytes‘-838:59:59’/‘838:59:59’HH:MM:SS时间值或持续时间
YEAR1 bytes1901/2155YYYY年份值
DATETIME8 bytes1000-01-01 00:00:00/9999-12-31 23:59:59YYYY-MM-DD HH:MM:SS混合日期和时间值
TIMESTAMP4 bytes1970-01-01 00:00:00/2038YYYY-MM-DD HH:MM:SS混合日期和时间值

具体用哪一种根据数据库的需求选择 ,长度越大,占内存越多,所以尽量选择适合的类型。
数据类型参考 : https://www.runoob.com/mysql/mysql-data-types.html

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值