使用shell命令操作数据库,shell命令数据库


使用mysql的-e参数可以执行各种sql的(创建,删除,增,删,改、查)等各种操作

用法

mysql  -uxxx    –pxxx   -e  “mysql 命令”

当然还可以使用 如下写法

mysql  -e  -uxxx    –pxxx    “mysql 命令”

实践出真知

[root@iZwz99qnmldt4n744noo9gZ ~]# mysql -e "show databases;" -uroot -ppenghui110 >test.txt
[root@iZwz99qnmldt4n744noo9gZ ~]# ls
databases_backup_20170411172702  lnmp1.3-full  lnmp-install.log  test.txt
[root@iZwz99qnmldt4n744noo9gZ ~]# cat test.txt 
Database
information_schema
blog
mysql
performance_schema
question
wordpress
yii2
[root@iZwz99qnmldt4n744noo9gZ ~]# mysql -uroot -ppenghui110  -e "show databases;"  >a.txt
[root@iZwz99qnmldt4n744noo9gZ ~]# cat a.txt 
Database
information_schema
blog
mysql
performance_schema
question
wordpress
yii2

参考文档:http://blog.csdn.net/feeltouch/article/details/46643065

相关内容