grant all on cookbook.* to ‘burness’on ‘localhost’ identified by ‘123456’
mysqldump –h localhost –u burness –p cookbook > cookbook.sql
生成的cookbook.sql内容如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | -- MySQL dump 10.13  Distrib 5.5.25, for Win64 (x86)---- Host: localhost    Database: cookbook-- -------------------------------------------------------- Server version   5.5.25/*!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 `couter`--DROPTABLEIF EXISTS `couter`;/*!40101 SET @saved_cs_client     = @@character_set_client */;/*!40101 SET character_set_client = utf8 */;CREATETABLE`couter` (  `depth` int(11) DEFAULTNULL) ENGINE=InnoDB DEFAULTCHARSET=latin1;/*!40101 SET character_set_client = @saved_cs_client */;---- Dumping data for table `couter`--LOCK TABLES `couter` WRITE;/*!40000 ALTER TABLE `couter` DISABLE KEYS */;INSERTINTO`couter` VALUES(1);/*!40000 ALTER TABLE `couter` ENABLE KEYS */;UNLOCK TABLES;---- Table structure for table `limbs`--DROPTABLEIF EXISTS `limbs`;/*!40101 SET @saved_cs_client     = @@character_set_client */;/*!40101 SET character_set_client = utf8 */;CREATETABLE`limbs` (  `thing` varchar(20) DEFAULTNULL,  `legs` int(11) DEFAULTNULL,  `arms` int(11) DEFAULTNULL) ENGINE=InnoDB DEFAULTCHARSET=latin1;/*!40101 SET character_set_client = @saved_cs_client */;---- Dumping data for table `limbs`--LOCK TABLES `limbs` WRITE;/*!40000 ALTER TABLE `limbs` DISABLE KEYS */;INSERTINTO`limbs` VALUES(‘human‘,2,2),(‘insect‘,6,0),(‘squid‘,0,10),(‘octopus‘,0,8),(‘fish‘,0,0),(‘centipede‘,100,0),(‘table‘,4,0),(‘armchair‘,4,2),(‘phonograhp‘,0,1),(‘tripod‘,3,0),(‘Peg Leg Pete‘,1,2),(‘space alien‘,NULL,NULL);/*!40000 ALTER TABLE `limbs` 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-04-25 20:41:18 | 
mysql cookbook < filename
eg:mysql cookbook < limbs.sql
limbs.sql内容如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | droptableif exists limbs;createtablelimbs(    thing varchar(20),    legs int,    arms int);insertintolimbs (thing,legs, arms) values(‘human‘,2,2);insertintolimbs (thing,legs, arms) values(‘insect‘,6,0);insertintolimbs (thing,legs, arms) values(‘squid‘,0,10);insertintolimbs (thing,legs, arms) values(‘octopus‘,0,8);insertintolimbs (thing,legs, arms) values(‘fish‘,0,0);insertintolimbs (thing,legs, arms) values(‘centipede‘,100,0);insertintolimbs (thing,legs, arms) values(‘table‘,4,0);insertintolimbs (thing,legs, arms) values(‘armchair‘,4,2);insertintolimbs (thing,legs, arms) values(‘phonograhp‘,0,1);insertintolimbs (thing,legs, arms) values(‘tripod‘,3,0);insertintolimbs (thing,legs, arms) values(‘Peg Leg Pete‘,1,2);insertintolimbs (thing,legs, arms) values(‘space alien‘,NULL,NULL); | 
或者使用source ,eg : source test.sql
mysql -u burness –p cookbook -e “select * from limbs where legs=0” >1.txt
mysql –H -u burness –p cookbook -e “select * from limbs where legs=0” >1.html
mysql –X -u burness –p cookbook -e “select * from limbs where legs=0” >1.xml
select * from limbs\G
mysql –u burness –p cookbook --tee=tmp.out cookbook
\T tmp.out
记录的命令及显示会输出到tmp.out
\t来停止记录
tmp.out 内容如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | Welcome tothe MySQL monitor.  Commands endwith; or\g.Your MySQL connectionid is12Server version: 5.5.25 MySQL Community Server (GPL)Copyright (c) 2000, 2011, Oracle and/orits affiliates. Allrights reserved.Oracle isa registered trademark ofOracle Corporation and/oritsaffiliates. Other names may be trademarks oftheir respectiveowners.Type ‘help;‘or‘\h‘forhelp. Type ‘\c‘toclear the currentinput statement.mysql> \T tmp.outmysql> use cookbook;Databasechangedmysql> select* fromlimbs;+--------------+------+------+| thing        | legs | arms |+--------------+------+------+| human        |    2 |    2 || insect       |    6 |    0 || squid        |    0 |   10 || octopus      |    0 |    8 || fish         |    0 |    0 || centipede    |  100 |    0 || table|    4 |    0 || armchair     |    4 |    2 || phonograhp   |    0 |    1 || tripod       |    3 |    0 || Peg Leg Pete |    1 |    2 || spacealien  | NULL| NULL|+--------------+------+------+12 rowsinset(0.00 sec)mysql> \t | 
@ var_name : value
eg: select @id := cust_id from customers where cust_id=’customer name’;
delete from orders where cust_id=@id;
delete from custers where cust_id=@id;
MySQL Cookbook学习笔记第一章,布布扣,bubuko.com
原文:http://www.cnblogs.com/burness/p/3690069.html