• MySQL数据库(一)



    1、操作数据库
    创建数据库:create database dbname;
    显示所有数据库:show databases;
    使用MySQL命令 show create database dbname;
    可以查看数据库的相关信息(例如MySQL版本ID号、默认字符集等信息)。
    选定默认数据库:use dbname;
    删除数据库,使用SQL语句 drop database dbname;


    2、操作数据库表的结构:
    创建数据库表之前必须先使用数据库。

    create table students(
    id int unsigned not null auto_increment primary key,
    name varchar(8) not null,
    sex char(4) not null,
    age int unsigned not null
    );ENGINE=InnoDB DEFAULT CHARSET=utf8;

    使用MySQL命令“desc students;”即可查看表名为table_name的表结构。

    使用MySQL命令“show create table students;”查看名为table_name表的详细信息。

    -- 添加列
    -- alter table 表名 add 列名 列数据类型 [after 插入位置];
    alter table students add birthday date after age ;
    -- 添加一列放在最前面
    alter table students add adress varchar (22) first;


    -- 修改列
    -- alter table 表名 change 列名称 列新名称 新数据类型
    alter table students change adress tel char(13) not null;
    -- 如果只对字段的数据类型进行修改
    -- alter table 表名 modify 字段名 新数据类型;


    -- 删除列
    -- alter table 表名 drop 列名称;
    alter table students drop sex;


    -- 重命名表
    -- alter table 表名 rename 新表名;
    alter table students rename newstudents;


    -- 删除整张表
    -- drop table 表名;
    drop table newstudents;

    -- 查看字符集
    -- 查看当前支持的MySQL字符集
    show charset;

    -- 使用MySQL命令
    show variables like 'character%';
    -- 即可查看当前MySQL服务实例使用的字符集。

  • 相关阅读:
    GDI+ 支持的图片文件格式
    Linux学习-灾难复原的考虑
    Linux学习-备份策略
    Linux学习-备份的种类、频率与工具的选择
    Linux学习-备份要点
    Linux学习-服务器硬件数据的收集
    Linux学习-系统基本设定
    Linux学习-开机过程的问题解决
    Linux学习-Boot Loader: Grub2
    Linux学习-核心与核心模块
  • 原文地址:https://www.cnblogs.com/nullcodeworld/p/8595553.html
Copyright © 2020-2023  润新知