添加数据 1 INSERT INTO  table_name ( field1, field2,... fieldN ) VALUES ( value1, value2,... valueN );
如果数据是字符型,必须使用单引号或者双引号,如:”value”。
 
删除数据 删除ttt表中id等于1的数据
1 delete from  ttt where  id =1 ;
插入字段 
alter table [表格名] Add column [要添加的字段] [字段类型] AFTER [哪个字段后面加];
 
在Password后插入一个char(8)类型的host字段
插入字段并判断有效值 
CHECK约束就是当向表中插入一行或更新一行数据时进行CHECK约束检查,CHECK接受一个表达式,如果这个表达式为TRUE则允许插入,如果这个表达式为FALSE则拒绝插入,在MariaDB10.2版本才开始支持CHECK。
 
alter table [表格名] add [要添加的字段] [字段类型] [check约束] after [哪个字段后面加];
 
要满足条件age=21或22才允许插入alter table userinfo add age int check(age=21 or age=22) after name;
删除字段 
alter table [表格名] drop column [要删除的字段名];
 
更新数据 
update [表格名] set [修改的内容] where [条件];
 
中文数据支持(修改编码格式) 正常插入一条中文数据会显示不出来,因为默认编码是latin1
查看数据库默认编码show variables like 'char%';
查看指定数据库默认编码show create database [数据库];
创建数据库指定字符集create database [数据库名称] character set utf8;
创建表指定字符集create table [表名和字段] charset=utf8; 
导入导出库和表 导出数据库和表 导出aaa库,以aaa.sql为文件名保存
1 mysqldump -u root -p123 aaa  > aaa . sql
导出aaa.ttt表,以ttt.sql为文件名保存
1 mysqldump  -u root -p123 aaa ttt > ttt.sql
导入数据库和表 导入aaa这个数据库aaa库
1 mysqldump -u root -p123 aaa  < aaa . sql
导入ttt表
1 2 MariaDB  [(none)] > use  aaa ;                      MariaDB  [aaa] > source  /root /ttt .sql            
导入txt 表结构
1 2 3 4 5 6 7 8 9 10 MariaDB [test]> desc sj; Field     | Type         | Null  | Key  | Default  | Extra  | ID        | int(11)      | NO    | PRI  | NULL     |        | Name      | varchar(10)  | YES   |      | NULL     |        | Day       | date         | YES   |      | NULL     |        | Password  | varchar(16)  | YES   |      | NULL     |        |
sql.txt内容
1 2 3 [root@localhost ~]# cat sql.txt-01 -02 ,zhangsan-06 -15 ,123456
表中已有内容
1 2 3 4 5 6 7 8 MariaDB [test]> select * from sj;+----+ --------+------------+ ------------------+| ID | Name   | Day        | Password         | +----+--------+------------+------------------+ |  2 | 二哈   | 1996-12-01 | 49973c3a8ab362ad | +----+--------+------------+------------------+ 
导入txt
1 2 3 MariaDB [test]> load  data local  infile '/root/sql.txt'  into  table  sj fields terminated by  ',' (ID,Name ,Day,@p) set  Password =md5(@p);2  rows  affected, 2  warnings (0.00  sec)2   Deleted: 0   Skipped: 0   Warnings: 2 
结果
1 2 3 4 5 6 7 8 9 10 MariaDB [test]> select *  from sj; ID  | Name    | Day         | Password          |  1  | w       | 1999-11-07  | f1290186a5d0b1ce  |  2  | 二哈    | 1996-12-01  | 49973c3a8ab362ad  |  3  | 张三    | 2000-01-02  | 01d7f40760960e7b  |  4  | 李四    | 2001-06-15  | e10adc3949ba59ab  |
命令解释load data local infile '/root/sql.txt'  //加载本地sql.txt文件into table sj   //导入sj这个表fields terminated by ','  //指明txt中分割数据的符号(ID,Name,Day,@p) set Password=md5(@p);  //字段名,md5(@p)表示md5加密前面定义的@p字段的内容