30 October, 2007

MySQL shell scripting

MySQL is the best. The best database server. I love it.
I like and appreciate its simplicity, efficiency, small size, good help, cool shell utilities. And its price :-)

I've worked with MySQL many years. And I can't understand some another database systems like Oracle, that big, heavy and high-priced. I can't stand theirs complexity.



You can use this server as you want. You can embed it into your application.
MySQL also pretty good in the console.

You can execute sql script from file e.g.:

data.sql

insert into Sample (name, address) values ('sample name', 'sample address');



with the simple command:

exec.cmd

@echo off
SET DATABASE_HOST=localhost
SET DATABASE_NAME=db
SET DATABASE_USER=root
SET DATABASE_PASSWORD=********

mysql -h %DATABASE_HOST% -u %DATABASE_USER% -p%DATABASE_PASSWORD% -e "source data.sql" %DATABASE_NAME%


and dump data from database with this command:

dump.cmd

@echo off
SET DATABASE_HOST=localhost
SET DATABASE_NAME=db
SET DATABASE_USER=root
SET DATABASE_PASSWORD=********

md tables
mysqldump --compact --no-create-info --tab=tables -h %DATABASE_HOST% -u %DATABASE_USER% -p%DATABASE_PASSWORD% %DATABASE_NAME%


For these purposes you should have only 2 files from mysql: mysql.exe and mysqldump.exe

No comments: