(syntax)mysql
2022-09-01 00:00:00

mysql

mysql

  • 数值:
    • tinyint、smallint、mediumint、int或integer、bigint 1\2\3\4\8
    • float、double 4\8Bytes
    • decimal 小数值
  • 日期/时间:
    • date 日期、time 时间、datetime 混合日期和时间值、 3 3 8
    • year 年份 1
    • timestamp(时间戳) 4
  • 字符串(字符)类型:
    • char 定长字符串 、varchar 变长字符串
    • tinyblob、blob、mediumblob、longblob(二进制形式)
    • tinytext、text、mediumtext、longtext

database create / drop / select / show / use + database

  • mysql -h 127.0.0.1 -u root -p
  • systemctl re/start mysqld
  • mysqladmin –version
  • use test; 使用数据库
  • create database test; 创建数据库
    • create database <数据库名> default charse=utf-8
  • drop database test; 删除数据库
  • show databases; 显示所有数据库
  • select database(); 查询所有的数据库

table show / create / insert into / drop / desc / rename / update / select from + table

  • show tables; 显示所有表
  • create table <表名> (<字段名1><类型1> [,..<字段名 n> <类型 n>]);
1
2
3
4
5
6
create table if not exists <表名>(
id int(4) not null primary key auto_increment,
name char(20) not null,
sex int(4) ,
degree double(16,2)
)engine = myisam default charset=utf8; // 表格中文乱码
  • insert into <表名>() values() 插入数据
    • insert into <表名>("id","name","age","sex") values (1,"zs","20","male"),(1,"zs","20","male")
  • create table <新表> select * from <旧表> / like 复制数据库
    • create table 新表 like 旧表
    • create table 新表 select * from 旧表
  • drop/delete from table <表名> 删除表
    • delete from <表名> where 名字=“”;
  • update 表名 set 字段=新值 更新数据
    • update student set 专业 = ’软件技术‘ where 姓名 = ’王丹‘;
  • rename table 原表名 to 新表名 更改表名
  • desc 表名; 获取表结构
  • select * from <表名> 查询所有行
    • select 列名1,列名2 from 表名;

limit 限制词

  • not(between and) 两者之间
    • select * from student where 学分 (not) between 15 and 20
  • as 别名
    • select 学号 as id,姓名 as name from student
  • and or 和 或
    • select * from student where 专业 = '软件技术' and/or 性别 = '男'
  • where 特定条件值
  • in / not in 是否匹配一个模式
    • select * from student where 姓名 )(not) in (’刘鑫‘);
  • like 模糊查询
    • select * from student where 姓名 like '王_/王__/王%'
  • order by 排序 / group by 分组
    • select * from MyClass order by id limit 0,2;
  • limit 限制条件
    • select * from MyClass limit 0,2;

import

  • mysqldump -u [数据库用户名] -p -A>[备份文件的保存路径]
  • mysqldump -h localhost -u root -p mydb(数据库名) mytable(数据库里面的表名)> c:\MySQL\mytable.sql
  • mysql> source [备份文件的保存路径]
上一页
2022-09-01 00:00:00
下一页