腳本學習之---菜鳥級別入門---mysql簡單刪除數據庫【三】

[root@demo scripts]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"mysql

+--------------------+sql

| Database           |vim

+--------------------+ide

| information_schema |spa

| binlog             |orm

| liu                |ip

| mysql              |it

| oldboy             |io

| performance_schema |form

| qq                 |

| riziwenjian        |

| shaopeng           |

| shujuku            |

| test               |

| uu                 |

| wodeshujk          |

| xindata            |

| zonglizhu          |

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

[root@demo scripts]# sh del.sh

[root@demo scripts]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

[root@demo scripts]# vim del.sh


#!/bin/sh

for dbname in `mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e"show databases"|sed '1,2d'|egrep -v "mysql|schema"`

do

       mysql -uroot -poldboy123 -S /data/3306/mysql.sock -e "drop database $dbname;"

done

相關文章
相關標籤/搜索