Category Archives: Database

Restore MySQL Database using mysqlbinlog

1.  Get log for database to restore $ mysqlbinlog –database=db_name mysql-bin.000001 > /tmp/db/restore.sql $ mysqlbinlog –database=db_name mysql-bin.000002 >> /tmp/db/restore.sql $ mysqlbinlog –database=db_name mysql-bin.000003 >> /tmp/db/restore.sql 2.  Edit restore.sql 3.  Execute SQL commands on restore.sql

Posted in Database | Tagged , | Leave a comment

selective mysqldump

$ mysqldump -uroot -p DB TBL –where=”COL_ID=3″ | grep INSERT

Posted in Database, MySQL | Tagged , , | Leave a comment

Extract particular table from a mysqldump file

$ awksqldump dbname.dump.sql tblname #!/bin/bash ### check parameter E_NO_ARGS=65 if [ $# -eq 2 ] then # Outputs string of specified table only awk “/Table structure for table .$2./,/UNLOCK TABLES/{print}” $1 > $1.EXTRACTED.sql elif [ $# -eq 3 ] then … Continue reading

Posted in Bash script, Database, Linux Administration, MySQL | Tagged , | Leave a comment

How to Create Database and Add User To It

Here are the SQL commands: create database newdb; grant CREATE,INSERT,DELETE,UPDATE,SELECT on newdb.* to newuser@localhost; SET PASSWORD FOR ‘newuser’@'localhost’ = password(‘newuserpass’); – or – SET PASSWORD FOR ‘newuser’@'localhost’ = old_password(‘newuserpass’); flush privileges;

Posted in Database, MySQL, Programming, SQL | Tagged , | Leave a comment