首页 > 教育

mysql如何在某个指定的数据库中建表

更新时间2018-03-16 07:54:08

如果在可视化界面,如phpMyAdmin中,可单击数据库,进入sql,写语句建表。
如果是在mysql控制台,则如下所示:
E:\Program Files (x86)\mysql\MySQL Server 5.6\bin>mysql -u root -p
Enter password: *********
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| edu |
| guest |
| mysql |
| performance_schema |
| sakila |
+--------------------+
11 rows in set (0.01 sec)
================--进入数据库
mysql> use edu;
Database changed
====================建表
mysql> create table blog(
-> bid mediumint(8) primary key auto_increment,
-> btitle varchar(60) ,
-> content text,
-> status tinyint(2),
-> cid tinyint(4)
-> );
Query OK, 0 rows affected (0.47 sec)

几种建表的方法:
// 建表名为 blog_blog
create table blog_blog(
bid mediumint(8) primary key auto_increment,
btitle varchar(60) ,
content text,
status tinyint(2),
cid tinyint(4)
)
//更改主键bid 为id
alter table blog_blog change bid id mediumint(8) auto_increment
// 建表名为 blog_channel
create table blog_channel(
cid tinyint(4) default null,
ctitle varchar(60) default null,
isshow tinyint(2) default '1'
)ENGINE = MyISAM DEFAULT CHARSET = gbk

相关标签:数据库mysql

上一篇:如何登录mysql?

下一篇:mysql主从同步开始用的master_log_pos点为77270703,同步失败