MySql处理数据库和表
2015-06-07 10:02
639 查看
show databases;
mysql> show databases;
mysql> create database db_test;
Query OK, 1 row affected (0.00 sec)
use
mysql> use db_test;
Database changed
似
mysqldrop
mysql> drop database db_test;
Query OK, 0 rows affected (0.00 sec)
MySQL
create table
MySQLcreate table
Query OK
tb_testtb_test2:
tb_test2
create select
MySQL
temporarycreate table
MySQLMySQLdrop table
show tables
describe
show
drop table
alter
create tablealter tabletb_demoemail
firstafterlast
emailnot null
email
mysql> show databases;
mysql> create database db_test;
Query OK, 1 row affected (0.00 sec)
use
mysql> use db_test;
Database changed
似
mysqldrop
mysql> drop database db_test;
Query OK, 0 rows affected (0.00 sec)
create table
mysql> create table tb_test( -> id int unsigned not null auto_increment, -> firstname varchar(25) not null, -> lastname varchar(25) not null, -> email varchar(45) not null, -> phone varchar(10) not null, -> primary key(id)); Query OK, 0 rows affected (0.03 sec)
mysql> create table db_test.tb_test( -> id int unsigned not null auto_increment, -> firstname varchar(25) not null, -> lastname varchar(25) not null, -> email varchar(45) not null, -> phone varchar(10) not null, -> primary key(id)); Query OK, 0 rows affected (0.03 sec)
MySQLcreate table
mysql> create table if not exists db_test.tb_test( -> id int unsigned not null auto_increment, -> firstname varchar(25) not null, -> lastname varchar(25) not null, -> email varchar(45) not null, -> phone varchar(10) not null, -> primary key(id)); Query OK, 0 rows affected, 1 warning (0.00 sec)
Query OK
tb_testtb_test2:
mysql> create table tb_test2 select * from db_test.tb_test; Query OK, 0 rows affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0
tb_test2
create select
mysql> describe tb_test; +-----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | firstname | varchar(25) | NO | | NULL | | | lastname | varchar(25) | NO | | NULL | | | email | varchar(45) | NO | | NULL | | | phone | varchar(10) | NO | | NULL | | +-----------+------------------+------+-----+---------+----------------+ 5 rows in set (0.01 sec) mysql> create table tb_test2 select id, firstname, lastname, email from tb_test; Query OK, 0 rows affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe tb_test2; +-----------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+-------+ | id | int(10) unsigned | NO | | 0 | | | firstname | varchar(25) | NO | | NULL | | | lastname | varchar(25) | NO | | NULL | | | email | varchar(45) | NO | | NULL | | +-----------+------------------+------+-----+---------+-------+ 4 rows in set (0.01 sec)
MySQL
temporarycreate table
mysql> create temporary table emp_temp select firstname, lastname from tb_test; Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0
MySQLMySQLdrop table
show tables
mysql> show tables; +-------------------+ | Tables_in_db_test | +-------------------+ | tb_test | | tb_test2 | +-------------------+ 2 rows in set (0.00 sec)
describe
mysql> describe tb_test; +-----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | firstname | varchar(25) | NO | | NULL | | | lastname | varchar(25) | NO | | NULL | | | email | varchar(45) | NO | | NULL | | | phone | varchar(10) | NO | | NULL | | +-----------+------------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec)
show
mysql> show columns in tb_test; +-----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | firstname | varchar(25) | NO | | NULL | | | lastname | varchar(25) | NO | | NULL | | | email | varchar(45) | NO | | NULL | | | phone | varchar(10) | NO | | NULL | | +-----------+------------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec)
drop table
drop [temporary] table [if exists] tbl_name [, tbl_name, ...]
alter
create tablealter tabletb_demoemail
mysql> alter table tb_demo add column email varchar(45); Query OK, 0 rows affected (0.14 sec) Records: 0 Duplicates: 0 Warnings: 0
firstafterlast
emailnot null
mysql> alter table tb_demo change email email varchar(45) not null; Query OK, 0 rows affected (0.11 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table tb_demo drop email; Query OK, 0 rows affected (0.09 sec) Records: 0 Duplicates: 0 Warnings: 0
相关文章推荐
- mysql数据库root密码忘记的修改方法
- MySQL 整体性能调优
- MySQL 中文显示乱码
- mysql数据库权限
- MySQL 中文乱码(全)
- mysql数据库按照同一字段不同值进行排序
- mysql 用户角色权限表建立
- 将MySQL转换为MMSQLServer2008实例过程
- MySql备份策略规划需要考虑的问题
- mysql常用命令总结
- 查看MYSQL数据库中所有用户及拥有权限
- mysql修改密码
- mysql 一张表update另一张表
- mysql旧表去重数据导入新表且赋予主键id新值
- ajax+jsp+servlet+mysql实现登陆验证
- MySQL Replication的Reset slave重置命令
- mysql在windows下两种安装方法
- MySQL索引原理及慢查询优化
- Mysql中的排序规则utf8_unicode_ci、utf8_general_ci的区别总结
- 第17章 Mysql复制