作法 1:直接在 shell sciprt 裡下 SQL
#! /bin/sh
mysql -u root -ppassword test << EOFMYSQL
SELECT * FROM test
EOFMYSQL
作法 2: 把 SQL 語法獨立成一個 .sql 檔
#! /bin/sh
mysql -u root -ppassword test < test.sql
註:上述語法若沒有指定資料庫的話,會直接對 test 做操作,想對其他資料庫做操作可以直接修改 test 為要操作資料庫名字,或是在 SQL 裡直接指定
全站熱搜