Archive

Posts Tagged ‘mysql’

How to optimize mysql database

April 10th, 2009 No comments

Recently I did run into issue where I just needed to optimize my database. Have few of them in mysql and then each of those databases have all bunch of tables. Now, I can issue:
mysql -u root -ppassword -e ‘show databases’
this will display list of all my databases, then I can connect to each individual database and issue the following sql statement:
OPTIMIZE TABLE tbl_name;
But this is quite manual process. Easier way is to just use mysqlcheck utility on the whole database rather than each individual tables.
mysqlcheck -o dspam -u root -ppassword
The mysqlcheck program can also be used to check (-c/-m/-C), repair (-r) and analyze (-a) the tables in a database. These commands can be done by using the CHECK, REPAIR and ANALYZE MySQL commands.

So anyway I did put this into some script and can easily execute it on every database that I have in my mysql
-=-=-=- END OF SCRIPT -=-=-=-
#!/usr/bin/ksh
STAMP=`date +%y%m%d.%H%M%S`
HOSTNAME=`/usr/bin/uname -n`
REMOTEHOSTNAME=”localhost”

mysqlpwd=’password’             ###This is why the file should be chmod 700
                                ###for the mysql user we are backing up.

for database in `/usr/local/mysql/bin/mysql -h $REMOTEHOSTNAME -u root -p$mysqlpwd -e ‘show databases’ | sed s/[\+\|]//g`
do
  if [ $database == Database ] || [ $database == test ]
  then
    echo $database
    continue
  else
    now=`date`
    echo “==========================================”
    echo “Optimizing $database on $REMOTEHOSTNAME:”
    echo “Start: $now”
    /usr/local/bin/mysqlcheck -h $REMOTEHOSTNAME -o $database -u root -p$mysqlpwd
    if [ $? -eq 0 ]
    then
      now=`date`
      echo “End:   $now”
      echo “Optimization of $database Successful.”
    else
      echo “!!! There was an error optimizing up MySQL $database on $REMOTEHOSTNAME”
    fi
    echo “”
    echo “==========================================”
    echo “”
    echo “”
fi     
done
-=-=-=- END OF SCRIPT -=-=-=-

Categories: mysql Tags: , ,

Sys Admin MySQL 5 Cluster with Solaris(TM) 10 Zones-ZFS-Resource Control

March 28th, 2009 No comments

Some time ago there used to be UNIX magazine called Sys Admin, it was great and I did like it a lot, had lots of great articles and practical how-to’s, then it just did disapear. I did capture one of those articles which I found quite usefull in creating mysql cluster but also it has great exmple on solris 10 zones nd resource control. Hope its author will not mind, but if he does I can take it down.

Sys Admin  MySQL 5 Cluster with Solaris(TM) 10 Zones-ZFS-Resource Control

 

Derek Crudgington

Read more…

Categories: 10, Solaris, zfs, zones Tags: , , , ,

zipcodes

March 10th, 2006 No comments

Playing with mysql database where I have created zipcode database with all the zips in the US, this is for the other work that I did play with setting up AJAX web interface for it.

 

mysql> connect zipcodes
Connection id:    159204
Current database: zipcodes

mysql> select * from zipcodes where zipcode = 11694;
+———+—————+——-+———-+
| zipcode | city          | state | areacode |
+———+—————+——-+———-+
|   11694 | Rockaway Park | NY    |      718 |
+———+—————+——-+———-+
1 row in set (0.02 sec)

Read more…

Categories: mysql Tags:

dspam and mysql

December 22nd, 2005 No comments

how to fix mysql db files when I could not start mysql because of a crash. easiest way was to fix db tables using myisamchk command.

[16:03:17] root@chrysek: /usr/local/mysql/var/dspam >
/etc/init.d/mysql.server stop
No mysqld pid file found. Looked for /usr/local/mysql/var/chrysek.

pid.
[16:03:19] root@chrysek: /usr/local/mysql/var/dspam >
/etc/init.d/mysql.server start
[16:03:23] root@chrysek: /usr/local/mysql/var/dspam > myisamchk -r -q dspam_token_data.MYI
- check record delete-chain
- recovering (with sort) MyISAM-table ‘dspam_token_data.MYI’
Data records: 6184409
- Fixing index 1
[16:06:17] root@chrysek: /usr/local/mysql/var/dspam >

Read more…

Categories: dspam Tags: , ,

Powered by WP Robot

Stop SOPAPowered by Yahoo! Answers