MySQL Common commands -- create command use, mysql -- create

Source: Internet
Author: User

MySQL Common commands -- create command use, mysql -- create

  • Create Database
create database db_test;create database if not exists db_test;drop databases if exists db_test;
  • Create Table
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);

Create a new table from a saved table

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: 0mysql> 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: 0mysql> 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)

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.