zoukankan      html  css  js  c++  java
  • mysql基础命令

    mysql数据库使用

    show databases;  #查看所有库
    show global variables like '%datadir%';  #查看库位置  一般默认在/var/lib/mysql下
    use mysql;  #进入mysql库
    select database();  #查看当前在哪个库
    create database aa;  #创建库
    drop database aa;  #删除库
    
    show tables;  #查看库中的表
    create table bb(id int,name varchar(10),lase varchar(10));  #创建表id,name,lase
    drop dable aa,bb  #删除多个表
    describe aa;  desc aa;  #查看表的结构
    show create table aaG  #查看表的属性
    
    alter table aa add phone char(10);  #添加phone列
    alter table aa drop phone;  #删除phone列
    rename table aa to cc;  #修改表名
    
    insert into 表名 (列1,列2,列3,,,) values (值1,值2,值3,,,)  #插入数据
    insert into aa values (值1,值2,值3,,,)  #插入数据
    
    select * from 表名;  #查看表中所有数据
    select id from aa;  #查看表中id列
    select * from aa where id=1;  #查看表中id=1这一列
    select * from aa where id>1 and id<5;  #查看表中id大于1小于5的数据
    
    create table aa as select * from cc;  #把cc表复制且创建aa表。
    insert into cc select * from aa;  # 把aa表数据复制到cc表,cc表是空的。
    
    delete from aa;  #清空表aa
    delete from aa where id=1;  #删除id=1的列数据
    
    update aa set name='123';  #将aa表中的名字都改为123
    update aa set name='123' where id=1;  #将aa表中id=1的名字修改为123
    
    #表连接:有某一个共同的列名
    #一个id和name:aa
    #一个id和sale:bb
    
    select * from aa join bb where aa.id=bb.id  #查看两个表连接
    select name,sela from aa join bb where aa.id=bb.id and name='list';  #查看名字为list的lase
    select * from aa join bb using(id);  #两个表有共同的列
    
  • 相关阅读:
    IDEA创建test测试类
    SpringBoot Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration
    Mysql在线加索引锁表归纳
    工作感悟--对上一份工作总结
    ESP8266获取网络NTP时间(转)
    Python中的CGI编程 config配置(windows、Apache) 以及后期的编写(转)
    CGI与FastCGI(转)
    JSON-RPC轻量级远程调用协议介绍及使用
    java插件化编程(动态加载)
    PF4J入门指南
  • 原文地址:https://www.cnblogs.com/wml3030/p/15380515.html
Copyright © 2011-2022 走看看