truncate table via command line in Linux

喜你入骨 提交于 2019-12-10 12:53:41

问题


I want to truncate one of my db table using mysqldump command so that I can place that command in sh file for executing it on daily basis. Do any one know about this command? Thanks in advance


回答1:


You can use mysql command line client to do it

mysql -h dbserver_hostname -e "truncate table schema_name.table_name"



回答2:


localhost=hostname
root=username
''=password
demo=db name
language=table name   

#to truncate a table from database
mysql -h localhost -u root -p'' demo -e "truncate table demo.language"



回答3:


I found this working well. Replace vars if you are not using it in a script.

mysql -Nse 'show tables' -D $DATABASE -u$USER -p$PWD | while read table; do echo "SET FOREIGN_KEY_CHECKS = 0;drop table \`$table\`;SET FOREIGN_KEY_CHECKS = 1;"; done | mysql $DATABASE -u$USER -p$PWD



来源:https://stackoverflow.com/questions/23441994/truncate-table-via-command-line-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!