mysql的使用

1.登录MySQL

单击开始->所有程序->MySQL命令提示符->输入密码root即可

2.MySQL的使用

  1. 创建数据库test1

    create database test1;  ||create  schema test1;
    
  2. 查看所有数据库

    show databases;
    
  3. 选择数据库test1

    use test1;
    
  4. 查看表信息

    show tables;
    
  5. 查看创建表的结构

    desc 表名;   ||describe 表名;
    
  6. 一次性的设置client,connection,results的字符集为GBK

    set names GBK;
    
  7. 查看mysql字符集

    show variables like 'character%';
    
  8. 向表中插入记录

    insert into  表名 values(‘’,‘’,‘’,‘’,‘’);
    
  9. 查询表中的信息

    select * from 表名;
    

    10.删除表

drop table 表名;
  1. 删除数据库

    drop database 数据库名;
    
  2. 查看服务实例支持的字符集,字符序

    show character set;
    

13.复制表结构

create table 新表名 like 原表名;

14.修改表名

rename table 原表名 to 新表名;

15.修改表

alter table 表名
	add 字段名1 数据类型 [约束条件] [first|after 字段名2];
	change 字段名1 新字段名 数据类型 [约束条件]  [first|after 字段名2];
	modify 字段名1 新数据类型 [约束条件] [first|after 字段名2];
	drop 字段名;
	rename [to] 新表名;

例如:

  • alter table ygb add yjyj char(2) not null first;
  • alter table ygb change yjyj xyz int(2) ;
  • alter table ygb modify y varchar(10);
  • alter table ygb drop address;
  • alter table ygb rename to yg;

16.关键字

  • 默认值:default ‘值’
  • 自增型:auto_increment(默认从1开始自增)
  • 设置取值范围:check(sex in(‘男’,‘女’)) || check(sex=‘男’ or sex=‘女’)

例如:

create table employees2(
	EmployeeID int(6) not null primary key auto_increment,
	Name char(10) not null,
	Education char(4) not null,
	Birthday date not null,
	Sex char(2) check(sex='男' or sex='女'),    ||  Sex char(2) check(Sex in('男','女')),
	WorkYear tinyint(1),
	Address varchar(20),
	PhoneNumber char(13),
	DepartmentID char(3) not null
);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值