您的位置:首页 > 数据库 > MySQL

【mysql】-常用命令

2017-03-29 09:07 429 查看
-------------------没有高大上的词藻,只想平平淡淡的写个博客。
打开mysql命令:
mysql –u用户名 –p密码;
C:\Users\zhou>mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
显示mysql数据库:
show databases;

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hibernate_first |
| itooexam |
| mysql |
| performance_schema |
| sonar |
| t_user |
| test |
| user |
+--------------------+
9 rows in set (0.01 sec)
切换到需要操作的数据库:
use database(指定数据库);
mysql> use user;
Database changed
显示指定数据库的数据表:
show tables from db(指定数据库);
mysql> show tables from user;
+-------------------+
| Tables_in_user |
+-------------------+
| t1 |
| t2 |
| t3 |
| tbl_test_int |
| tbl_test_measure |
| tbl_test_relation |
| v_t1 |
+-------------------+
7 rows in set (0.00 sec)
创建test1表:
 mysql> create table test1(
-> id int unsigned not null auto_increment primary key,
-> name varchar(30)
-> );
Query OK, 0 rows affected (0.07 sec)
查看test1表结构:
 mysql> desc test1;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
为表插入一条数据:
 mysql> insert into test1(name) values("user1");
Query OK, 1 row affected (0.07 sec)
复制test1表为test2表:
 mysql> create table test2 like test1;
Query OK, 0 rows affected (0.13 sec)
查看test2表结构:
 mysql> desc test2;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
将表test1的数据插入到test2:
 mysql> insert into test2 select * from test1;
Query OK, 2 rows affected (0.05 sec)
Records: 2 Duplicates: 0 Warnings: 0
注意:如果test1,test2这两个表结构是一致的,那么使用test1的数据直接插入到test2里面是可以成功的。但是如果是部分复制test1的话就会出现一定的问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: