MySQL Cookbook学习笔记第一章

1,create databse cookbook

2,给数据库cookbook创建一个用户burness,密码为123456

grant  all on cookbook.* to ‘burness’on ‘localhost’ identified by ‘123456’

3,生成一个备份

mysqldump –h localhost –u burness –p cookbook > cookbook.sql

生成的cookbook.sql内容如下:

4,mysql从文件中读取语句

mysql cookbook < filename

eg:mysql cookbook < limbs.sql

limbs.sql内容如下:

或者使用source ,eg : source test.sql

5,mysql还能使用pipe使用程序的查询命令

6,输出重定向:-H -X可以生成HTML,XML内容

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

MySQL Cookbook学习笔记第一章MySQL Cookbook学习笔记第一章

7,当过长的查询输出到屏幕需要一行来垂直地显示输出使用\G代替;

select * from limbs\G

MySQL Cookbook学习笔记第一章

8,记录交互式的mysql对话

mysql –u burness –p cookbook --tee=tmp.out cookbook

\T tmp.out

记录的命令及显示会输出到tmp.out

\t来停止记录

tmp.out 内容如下:

9,在mysql中使用自己定义的变量

@ 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

MySQL Cookbook学习笔记第一章

上一篇:镜像数据库日志截断方法


下一篇:PHP 配置MYSQL (MY.INI)