Mysql 基本使用

摘自mysql

21分钟 MySQL 入门教程sql

1.登录/退出shell

    mysql -u 用户名 -p    #-u 所要登录的用户名,-p 使用密码登录
    exit;/quit;        #退出登录

2.数据库操做数据库

    建立ui

        create database 数据库名[其余选项]    #[] 为可选内容

            其余选项: character set gbk    #将数据库的字符编码指定为编码

    查看全部数据库code

        show databases

    选择要操做的数据库教程

        use 数据库名it

        登录时选择数据库:mysql -D 所选择的数据库名 -h 主机名 -u 用户名 -p字符编码

3.表操做

    建立

        create table tablename(columns)     #建立数据库表的命令

                                    #列的名称以及该列的数据类型将在括号内完成;

    插入数据

        insert into 表名[(列名1,列名2...)] values(值1,值2...);

    查询数据

        select 列名称 from 表名称[查询条件];

                    查询条件: where 条件        # where 关键字用于指定查询条件

    更新数据

        update 表名称 set 列名称=新值 where 更新条件;

    删除数据

        delete from 表名称 where 删除条件;

    建立后表的操做    alter table

        添加列

            alter table 表名 add 列名 列数据类型 [after 插入位置]

        修改列

            alter table 表名 change 列名 新列名 列数据类型;

        删除列

            alter table 表名 drop 列名称;

    重命名表

        alter table 表名 rename 新表名

    删除整张表

        drop table 表名;

    删除整个数据库

        drop database 数据库名
相关文章
相关标签/搜索