zoukankan      html  css  js  c++  java
  • MySQL经常使用命令--create命令使用

    • 切换数据库的字符集
    在mysql中的配置文件里:
    使用vim /etc/mysql/my.cnf
    [client]
    default-character-set = utf8
    [mysqld]
    character-set-server = utf8
    这当中的mysql的版本号是mysql 5.6系列的
    • create 数据库
    create database db_test;
    create database if not exists db_test;
    drop databases if exists db_test;
    • create 表
    create table if not exists t_user(
        uid varchar(50) not null,
        account_kind enum("stock","future"),
    
        stock_cash varchar(30),
        stock_sh varchar(30),
        stock_sz varchar(30),
        stock_pwd varchar(50),
    
        future_BrokerID varchar(30),
        future_InvestorID varchar(30),
        future_pwd varchar(50),
    
        unique key(stock_cash,stock_sh,stock_sz,stock_pwd),
        unique key(future_BrokerID,future_InvestorID,future_pwd),
        primary key(uid),
        index STOCKINFO(stock_cash,stock_sh,stock_sz,stock_pwd)
    
    )ENGINE=MyISAM DEFAULT CHARSET=utf8;

    you can also use this to create index

    create table t_TEST(
    id int not null, 
    name varchar(10)
    );
    create index IDX_TEST_Name on t_TEST(name);

    将从一个已经存储好的表中创建一个新的表

    mysql> select * from t_subscribe;
    +------+-------------+---------------------+
    | uid  | strategy_id | date                |
    +------+-------------+---------------------+
    | 1233 | 123414      | 2015-06-11 10:19:52 |
    | 0    | 0           | 2015-06-11 10:19:52 |
    | 1    | 1           | 2015-06-11 10:19:52 |
    | 2    | 2           | 2015-06-11 10:19:52 |
    | 3    | 3           | 2015-06-11 10:19:52 |
    | 4    | 4           | 2015-06-11 10:19:52 |
    | 5    | 5           | 2015-06-11 10:19:52 |
    | 6    | 6           | 2015-06-11 10:19:52 |
    | 7    | 7           | 2015-06-11 10:19:52 |
    | 8    | 8           | 2015-06-11 10:19:52 |
    | 9    | 9           | 2015-06-11 10:19:52 |
    +------+-------------+---------------------+
    11 rows in set (0.00 sec)
    
    mysql> create table test select * from t_subscribe;
    Query OK, 11 rows affected (0.03 sec)
    Records: 11  Duplicates: 0  Warnings: 0
    
    mysql> select * from test;
    +------+-------------+---------------------+
    | uid  | strategy_id | date                |
    +------+-------------+---------------------+
    | 1233 | 123414      | 2015-06-11 10:19:52 |
    | 0    | 0           | 2015-06-11 10:19:52 |
    | 1    | 1           | 2015-06-11 10:19:52 |
    | 2    | 2           | 2015-06-11 10:19:52 |
    | 3    | 3           | 2015-06-11 10:19:52 |
    | 4    | 4           | 2015-06-11 10:19:52 |
    | 5    | 5           | 2015-06-11 10:19:52 |
    | 6    | 6           | 2015-06-11 10:19:52 |
    | 7    | 7           | 2015-06-11 10:19:52 |
    | 8    | 8           | 2015-06-11 10:19:52 |
    | 9    | 9           | 2015-06-11 10:19:52 |
    +------+-------------+---------------------+
    
    mysql> insert into test select * from t_subscribe;
    Query OK, 11 rows affected (0.00 sec)
    Records: 11  Duplicates: 0  Warnings: 0
    
    mysql> select * from test;
    +------+-------------+---------------------+
    | uid  | strategy_id | date                |
    +------+-------------+---------------------+
    | 1233 | 123414      | 2015-06-11 10:19:52 |
    | 0    | 0           | 2015-06-11 10:19:52 |
    | 1    | 1           | 2015-06-11 10:19:52 |
    | 2    | 2           | 2015-06-11 10:19:52 |
    | 3    | 3           | 2015-06-11 10:19:52 |
    | 4    | 4           | 2015-06-11 10:19:52 |
    | 5    | 5           | 2015-06-11 10:19:52 |
    | 6    | 6           | 2015-06-11 10:19:52 |
    | 7    | 7           | 2015-06-11 10:19:52 |
    | 8    | 8           | 2015-06-11 10:19:52 |
    | 9    | 9           | 2015-06-11 10:19:52 |
    | 1233 | 123414      | 2015-06-11 10:19:52 |
    | 0    | 0           | 2015-06-11 10:19:52 |
    | 1    | 1           | 2015-06-11 10:19:52 |
    | 2    | 2           | 2015-06-11 10:19:52 |
    | 3    | 3           | 2015-06-11 10:19:52 |
    | 4    | 4           | 2015-06-11 10:19:52 |
    | 5    | 5           | 2015-06-11 10:19:52 |
    | 6    | 6           | 2015-06-11 10:19:52 |
    | 7    | 7           | 2015-06-11 10:19:52 |
    | 8    | 8           | 2015-06-11 10:19:52 |
    | 9    | 9           | 2015-06-11 10:19:52 |
    +------+-------------+---------------------+
    22 rows in set (0.00 sec)
  • 相关阅读:
    C++——string转char[]
    Ackerman的非递归算法(未解决)
    单链表——递归求最大整数、节点个数、平均值
    队列——以数组Q[m]存放循环队列元素,设置一个标志tag,以tag=0和tag=1来区别在头指针和尾指针相等时,队列为空或满
    队列——假设以带头结点的循环链表表示队列,并且只设一个指针指向队尾元素结点(注意:不设头指针), * 试编写相应的置空队列、判断队列是否为空、入队和出队等算法。
    栈——判断回文
    栈——表达式求值
    栈——匹配()[]
    栈——十进制转八进制
    动态获取导航栏
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7246712.html
Copyright © 2011-2022 走看看