MySQL 資料庫操作

備份

mysqldump -u ${username} -p"${password}" -R ${old_dbname} > ${tmp_sql_dump_path}

匯入

mysql -u ${username} -p"${password}" ${new_dbname} < ${tmp_sql_dump_path}

刪除

mysqladmin -u ${username} -p"${password}" DROP ${old_dbname}

Rename

重新命名DB其實沒有一個指令可以完成,但可利用dump/create/import/drop的方式

# dump
mysqldump -u ${username} -p"${password}" -R ${old_dbname} > ${tmp_sql_dump_path}
# create new
mysqladmin -u ${username} -p"${password}" CREATE ${new_dbname}
# import
mysql -u ${username} -p"${password}" ${new_dbname} < ${tmp_sql_dump_path}
# drop old db
mysqladmin -u ${username} -p"${password}" DROP ${old_dbname}

results matching ""

    No results matching ""