MySQL is quite new to use and Pearl has a whole newbie but to help me hack an ales script I am trying to do I got the script from me, it looks good so far, but it fails because there are some foreign key checks in the tables. I can go through phpmyadmin and try and delete them all at one go but it takes forever and this is my third time: (My question is, what is included in this script:
`SET FOREIGN_KEY_CHECKS = 0; Before it runs the drop table command? I tried to follow the script, but one of the scripts Fixed Command not found part (possibly ignorance / lack of understanding) The help was greatly appreciated.
Use the #! / Usr / bin / perl strict; use the DBI; my $ hostname = ';; my $ database =';; my $ User name = ''; my $ password = ''; my $ dbh = dbi- & gt; connect ("dbi: mysql: $ {database}: $ hostname", $ user name, $ password) or die "error: $ Dbi :: errstr \ n "; My $ sth = $ dbh- & gt; Ready (" Show Tab "); $ sth-> Executed or Die" SQL Error: $ DBI :: errstr \ n "; My $ I = 0; my @all_tables = (); while (my $ table = $ st H-& gt; fetch_array) {$ i ++; Print "table $ i: $ table \ n"; Push @all_tables, $ table;} my $ total_table_count = $ I; Print "Enter string or ridge to match tables". "Delete (not yet deleted):"; My $ regex = & lt; STDIN & gt; Chomp $ regex; $ I = 0; My @matching_tables = (); Prefer my $ Table (@ All_Tables) {if ($ table = ~ / $ regex / i) {$ i ++; Print "mailing table $ i: $ table \ n"; Push @ matching_tables, $ tables; }} My $ match_table_count = $ i; If ($ matching_table_count) {print "$ total_table_count $ out_table_count $ off_table_count" "matches tables, and will be removed. \ N"; Print "Now Delete Table? [Y / n]"; My $ decision = & lt; STDIN & gt; Chomp $ decision; $ I = 0; If ($ decision = ~ / y / i) {foreach my $ table (@ matching_tables) {$ i ++; Print "table $ i: $ table deletion \ n"; My $ sth = $ dbh- & gt; Prepare ("Drop Table $ Table"); $ Sth- & gt; Executed or died "SQL error: $ DBI :: errstr \ n"; }} Else {print} "No tables are being deleted. \ N"; }} And {print "no matching table. \ N"; }
Setting to Zero:
SET FOREIGN_KEY_CHECKS = 0; ... foreign key barriers will be widely disabled before the drop script. Because you can have more than one catalog / database on a MySQL example, it puts an impact on the risk database and others.
Normal habit is to be scripted in the order of main dependency, removing / deleting data from the parent table before the children.
Comments
Post a Comment