Solved

HowTo repair/optimize all tables in ssh?

Posted on 2008-10-02
4
1,492 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query Peformance + mulitple query plans 9 48
mysql joining from the same table 6 36
Sql Join Problem 2 33
running code or pseudo code of table structure 5 9
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

867 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

20 Experts available now in Live!

Get 1:1 Help Now