zoukankan      html  css  js  c++  java
  • mysql经常使用的命令

    如何登陆数据库
        飞机着陆
        mysql -u <username> -p

        访问本机数据库
        mysql -u <username> -D <database_name> -p

        登陆远程某个数据库
        mysql -h <hostname> -u <username> -D <database_name> -p
        
        登陆远程某个数据库,从特定port
        mysql -h <hostname> -P <port> -u <username> -D <database_name> -p

    怎样运行sql脚本
        mysql > source <scriptname.sql>

    怎样參看有哪些库
        show databases
        
    怎样切换数据库
        use <database_name>

    怎样參看库中有哪些表
        show tables
        
    怎样查看正在使用哪个数据库

        status

    查看数据状态,參数

    show status

    改动mysqlpassword
    mysqladmin -u root -p password {new_password}

    同意mysql远程连接
    update user set host = '%' where user = 'root';

    查询表定义
    show create table {table_name};

    show columns from {table_name};

    describe {table_name};



    创建数据库
        create database {databas_name}

    删除数据库
        drop database {databas_name}

    新建表
        create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

        create table table1(
        -> col1 int primary key,
        -> col2 int,
        -> col3 varchar(30),
        -> )
        -> ;

        create table Teacther
        (
        tNo int primary key,
        tName varchar(50) not null,
        tSex  varchar(2) not null check (tsex in ('男','女')),
        tBirthDate datetime not null,
        tSalary decimal(18,2),
        tHairDate datetime,
        depNo int
        foreign key(depNo) references Depart(depNo)
        )

    依据已有的表创建新表
        create table {new_table_name} like {old_table_name}
        create table {new_table_name} as select {[col1_name],[col2_name}, …} from {old_table_name} definition only

    插入数据
        insert into {table_name} (field1,field2) values(value1,value2);
        insert into table1 (col1,col2,col3) values(1,1,"aaa");

    更新数据
        update {table_name} set {field1}={value1} where {condition};
        update table1 set col3="zzz" where col1=1;

    查询数据
        select {field1,field2} from {table_name} where {condition};
        select * from table1;

        select distinct {column} from {table_name} 显示唯一值

        select {column} from {table_name} limit {num} 限制检索的行数

        select {column} from {table_name} limit {num1, num2} 从第num1開始的num2个行

        select {column} from {table_name} order by {column} desc; 按降序排列
        select {column} from {table_name} where {column} between {num1} and {num2} 范围查找

        select {column} from {table_name} where {column} is null 查找空值

        select from where group by having order by limit
    删除数据
        delete from {table_name} where {condition};
        delete from table1 where col1=2;


    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    flask 源码专题(七):threading.local和高级
    flask 源码专题(六):session处理机制
    flask 源码专题(五):SqlAlchemy 中操作数据库时session和scoped_session的区别
    flask 源码专题(四):wtforms Form实例化流程以及csrf验证
    flask 源码专题(三):请求上下文和应用上下文入栈与出栈
    python 追踪函数调用
    flask 源码专题(一):app.run()的背后
    flask 源码专题(二):请求上下文与全文上下文
    边框间距 | border-spacing (Miscellaneous Level 2)
    边框样式属性 | border-top-style (Backgrounds & Borders)
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4662784.html
Copyright © 2011-2022 走看看