mysql常用命令总结_mysql常用命令总结

1.连接至mysql

C:\mysql-advanced-5.6.15-winx64\bin>mysql -u root -p

Enter password: ******

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.15-enterprise-commercial-advanced MySQL Enterprise Server -

Advanced Edition (Commercial)

Copyright (c) 2000, 2013, 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.

2.创建数据库

mysql> create database hbhe;

Query OK, 1 row affected (0.01 sec)

3.连接至数据库

mysql>use hbhe;

Database changed

4.显示数据库

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| hbhe               |

| mysql              |

| performance_schema |

| sakila             |

| test               |

| world              |

+--------------------+

7 rows in set (0.01 sec)

5.删除数据库

mysql> drop database hbhe;

Query OK, 0 rows affected (0.01 sec)

6.创建数据库表

mysql> use hbhe;

Database changed

mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));

Query OK, 0 rows affected (0.09 sec)

7.显示表结构

mysql>DESCRIBE MYTABLE;

+-------+-------------+------+-----+---------+-------+

| Field | Type        | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| name  | varchar(20) | YES  |     | NULL    |       |

| sex   | char(1)     | YES  |     | NULL    |       |

+-------+-------------+------+-----+---------+-------+

2 rows in set (0.01 sec)

8.在表中加入数据

mysql> insert into MYTABLE values("hbhe","M");

Query OK, 1 row affected (0.01 sec)

9.更新表

mysql> update MYTABLE set sex="f" where name = 'hbhe';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0

10.清空表

mysql> delete from mytable;

Query OK, 1 row affected (0.02 sec)

11.删除表

mysql> drop table mytable;

Query OK, 0 rows affected (0.03 sec)

12.更改表名

mysql> rename table mytable to yourtable;

Query OK, 0 rows affected (0.03 sec)

13.导出hbhe库信息

C:\mysql-advanced-5.6.15-winx64\bin>mysqldump -u root -p hbhe >hbhe.sql

Enter password: ******

库信息如下

-- MySQL dump 10.13  Distrib 5.6.15, for Win64 (x86_64)

--

-- Host: localhost    Database: hbhe

-- ------------------------------------------------------

-- Server version5.6.15-enterprise-commercial-advanced

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;

/*!40103 SET TIME_ZONE='+00:00' */;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--

-- Table structure for table `yourtable`

--

DROP TABLE IF EXISTS `yourtable`;

/*!40101 SET @saved_cs_client     = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `yourtable` (

`name` varchar(20) DEFAULT NULL,

`sex` char(1) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*!40101 SET character_set_client = @saved_cs_client */;

--

-- Dumping data for table `yourtable`

--

LOCK TABLES `yourtable` WRITE;

/*!40000 ALTER TABLE `yourtable` DISABLE KEYS */;

/*!40000 ALTER TABLE `yourtable` ENABLE KEYS */;

UNLOCK TABLES;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2014-02-10 19:14:11

14.导出一张表

C:\mysql-advanced-5.6.15-winx64\bin>mysqldump -u root -p hbhe yourtable > yourtable.sql

Enter password: ******

yourtable表中内容如下:

-- MySQL dump 10.13  Distrib 5.6.15, for Win64 (x86_64)

--

-- Host: localhost    Database: hbhe

-- ------------------------------------------------------

-- Server version5.6.15-enterprise-commercial-advanced

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;

/*!40103 SET TIME_ZONE='+00:00' */;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--

-- Table structure for table `yourtable`

--

DROP TABLE IF EXISTS `yourtable`;

/*!40101 SET @saved_cs_client     = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `yourtable` (

`name` varchar(20) DEFAULT NULL,

`sex` char(1) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*!40101 SET character_set_client = @saved_cs_client */;

--

-- Dumping data for table `yourtable`

--

LOCK TABLES `yourtable` WRITE;

/*!40000 ALTER TABLE `yourtable` DISABLE KEYS */;

INSERT INTO `yourtable` VALUES ('hbhe','M');

/*!40000 ALTER TABLE `yourtable` ENABLE KEYS */;

UNLOCK TABLES;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2014-02-10 19:21:33

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值