找回密码
 立即注册

DSC65_汪汪队

新手上路

  • 5

    积分

  • 1

    帖子

  • 0

    精华

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
一、引入数据库概念
关系型数据库:Oraclemysqlsql server
非关系型数据库:hbaseredismangodb
  • 安装MySQL
    查看是否有安装过mysqlrpm -qa|grep -i mysql
    客户端Yum install MySQL
    服务端Yum install mysql-server
  • mysql命令

  • 启动、重启、停止:service mysqld start/restart/stop
  • 查看mysql状态、以及mysqlpid码: service mysqld status
  • 设置mysql密码:mysqladmin -uroot -password123456
  • 登录:mysql -uroot -p123456
  • 退出:exit/ctrl+c
  • 查看所有数据库:show databases
  • 切换数据库:use dcs65
  • 查看目前所处数据库:select database();
  • 新建数据库:create database dcs65;  create database if not exist dcs65
  • 删除数据库:drop database dcs65;   drop database if exist dcs65
  • 查看数据库中所有表:show tables;
  • 查看表结构:desc test1
  • 修改表名:alter table rename test1 test
  • 修改字段名并取消自增长约束:alter table test1 change id sid int20);
  • 修改字段名并添加自增长约束:alter table test1 change sid id int20auto_increment;
  • 添加字段到首位:alter table test1 add class int20first
  • 添加字段到某个字段后:alter table test1 add sex int(20) after id;
  • 修改某个字段的位置:alter table test1 modify class int20after id
  • 添加两个字段:alter table test1 add(age1 int(20),age2 int(20));
  • 删除表中字段:alter table test1 drop sex;
  • 同时删除多个字段:alter table drop age1,drop age2;
  • 删除字段的自增约束:alter table test1 change id id int(20);
  • 删除字段的主键约束:alter table test1 drop primary key
  • 添加主键及自增约束:alter table test1 change id id int(20) primary key auto_increment;
  • 删除表:drop table test1
  • 新建表:create table test1(id int(20) primary key auto_increment,score float(20,2) not null,name varchar(20),phone bigint(20) default 13577778888,time date)
  • 查看表中所有内容:select * from test;
  • 插入数据:insert into test1(id,score,name,phone,time() values(2,99,xiaoer,13577778888,2021-08-07)                                                                                          

  • 数据类型

  • Int()整型 最大的存储值是2147483647,10
  • Bigint()长整型 手机号用
  • Float()浮点型 比如float20,22是精度
  • Char()字符 单个字符
  • Varchar()长字符
  • data日期型
  • 只有字符型和日期型的数据需要加单引号或双引号

  • 字段的约束

  • Primary key 主键约束 唯一值
  • Auto_increment 自增长约束,和主键约束搭配使用
  • Not null 非空约束
  • Default 默认约束,无输入时默认时13577778888






分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册