Solved

HowTo repair/optimize all tables in ssh?

Posted on 2008-10-02
4
1,491 Views
Last Modified: 2008-10-15
HowTo repair/optimize all tables in ssh?
this line repair only one table, but how to repair them all?
repair table ibf_posts;
0
Comment
Question by:Stepa6ka
  • 2
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22631662
you can use the sp_msforeachtable strored procedure in sql server
0
 

Author Comment

by:Stepa6ka
ID: 22631877
and how can i use it in mysql?
0
 

Author Comment

by:Stepa6ka
ID: 22635091
Help me please... :/
0
 
LVL 29

Accepted Solution

by:
Michael W earned 500 total points
ID: 22650465
Here's a script I found via Google search that does both optimize and repair...

Reference:
http://www.adspeed.org/2007/01/mysql-shell-script-to-optimize-all.html

#!/bin/sh
 

# this shell script finds all the tables for a database and run a command against it

# @usage "mysql_tables.sh --optimize MyDatabaseABC"

# @date 6/14/2006

# @version 1.1 - 1/28/2007 - add repair

# @version 1.0 - 6/14/2006 - first release

# @author Son Nguyen
 

DBNAME=$2
 

printUsage() {

  echo "Usage: $0"

  echo " --optimize <dbname>"

  echo " --repair <dbname>"

  return

}
 
 

doAllTables() {

  # get the table names

  TABLENAMES=`mysql -D $DBNAME -e "SHOW TABLES\G;"|grep 'Tables_in_'|sed -n 's/.*Tables_in_.*: \([_0-9A-Za-z]*\).*/\1/p'`
 

  # loop through the tables and optimize them

  for TABLENAME in $TABLENAMES

  do

    mysql -D $DBNAME -e "$DBCMD TABLE $TABLENAME;"

  done

}
 

if [ $# -eq 0 ] ; then

  printUsage

  exit 1

fi
 

case $1 in

  --optimize) DBCMD=OPTIMIZE; doAllTables;;

  --repair) DBCMD=REPAIR; doAllTables;;

  --help) printUsage; exit 1;;

  *) printUsage; exit 1;;

esac

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now