shell - How do I truncate all data in my MySQL database? -


i'm using mysql 5.5 on mac 10.7.5. shell (i'm using bash), i'd able run command o truncate data in tables. also, i'd enter single command won't prompt me password. i've tried this, found on post, no dice. shell command can use truncate database table data?

mysql -umyuser -p -e 'set foreign_key_checks = 0; show tables' my_db | while read table; mysql -e -umyuser -p "truncate table $table" my_db; done enter password:   mysql  ver 14.14 distrib 5.5.25, osx10.6 (i386) using readline 5.1 copyright (c) 2000, 2011, oracle and/or affiliates. rights reserved.  oracle registered trademark of oracle corporation and/or affiliates. other names may trademarks of respective owners.  usage: mysql [options] [database]   -?, --help          display , exit.   -i, --help          synonym -?   --auto-rehash       enable automatic rehashing. 1 doesn't need use                   'rehash' table , field completion, startup                   , reconnecting may take longer time. disable                   --disable-auto-rehash.                   (defaults on; use --skip-auto-rehash disable.)   -a, --no-auto-rehash                   no automatic rehashing. 1 has use 'rehash'                   table , field completion. gives quicker start of                   mysql , disables rehashing on reconnect.   --auto-vertical-output                   automatically switch vertical output mode if                   result wider terminal width.   -b, --batch         don't use history file. disable interactive behavior.                   (enables --silent.)   --character-sets-dir=name                   directory character set files.   --column-type-info  display column type information.   -c, --comments      preserve comments. send comments server.                   default --skip-comments (discard comments), enable                   --comments.   -c, --compress      use compression in server/client protocol.   -#, --debug[=#]     non-debug version. catch , exit.   --debug-check       check memory , open file usage @ exit.   -t, --debug-info    print debug info @ exit.   -d, --database=name database use.   --default-character-set=name ... 

you can dump database without data:

mysqldump -u myuser -p --databases --add-drop-database --no-data my_db > my_db.sql 

and restore after that

mysql -u myuser -p < my_db.sql 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -