mysql基本操作记录
程序员文章站
2024-01-30 16:26:28
...
创建库名
create database 数据库库名;
显示目前所有的库
show databases;
创建表
create table test_table (
-> id integer,
-> name varchar(30),
-> age integer,
-> point decimal(6,2),
-> brief varchar(30)
-> );
Query OK, 0 rows affected (0.01 sec)
插入数据
insert into test_table
-> (id, name, age, point, brief)
-> values
-> (123, "张三", 40, 6.32, "七里香")
-> ;
Query OK, 1 row affected (0.00 sec)
insert into test_table
-> (id, name, age, point, brief, embedding)
-> values
-> (123, "李四", 45, 9.32, "八达岭","[1:5,2:7,3:10]"),
-> (456, "王二五", 45, 9.32, "九庭院","[1:5,2:7,3:10]"),
-> (456, "王二五", 75, 19.32, "十里街","[1:15,2:17,3:110]")
-> ;
增加列名
alter table test_table add column embedding char(50);
列的类型
主要分数值类型、日期类型和字符串类型。这里简单说明下:
- 数值类型:通常int、double、float、decimal、bigint
- 日期类型:通常date、datetime、timestamp
- 字符串类型:char、varchar、text
具体可以参考:Mysql菜鸟教程之Mysql数据类型
删除列名
alter table test_table drop column ebedding;
删除某一行
delete from test_table where id is null;
更新值
update test_table set embedding = "[1:3,2:5,3:6]" where id = 123;
增加索引
增加索引有两种方式:create 和 alter
create
增加普通索引(该索引可重复)
create index id on test_table (id);
增加唯一索引(该索引不可重复)
create unique index id on test_table (id);
alter
ALTER table test_table ADD INDEX id(id);
查看索引
show index from test_table;
删除索引
drop index id on test_table;
ALTER TABLE test_table DROP INDEX id;
自增长
CREATE TABLE insect
-> (
-> id INT UNSIGNED NOT NULL AUTO_INCREMENT,
-> PRIMARY KEY (id),
-> name VARCHAR(30) NOT NULL, # type of insect
-> date DATE NOT NULL, # date collected
-> origin VARCHAR(30) NOT NULL # where collected
);
下一篇: 安装go 1.13