Skip to main content

Posts

Showing posts with the label mysql

CronJob

Example Example: Insert a record into a database every one minute. 1. Create a .sh file ----insertsms.sh--- mysql -N -u root -e "use database; INSERT INTO table1 (project_id,feedback_id, text)VALUES (5,201,'Thank you,  I am ALWAYS happy with the service I receive from .......');" 2. Run command in the command line # crontab -e 3.   Append the following entry: 0-59 * * * * /root/ insertsms  .sh save the file More Examples To run /path/to/command five minutes after midnight, every day, enter: 5 0 * * * /path/to/command Run /path/to/script.sh at 2:15pm on the first of every month, enter: 15 14 1 * * /path/to/script.sh Run /scripts/phpscript.php at 10 pm on weekdays, enter: 0 22 * * 1-5 /scripts/phpscript.php Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter: 23 0-23/2 * * * /root/scripts/perl/perlscript.pl Run /path/to/unixcommand at 5 after 4 every Sunday, enter: 5 4 * * sun /p...

Backup and Restore MySQL Database Using mysqldump

mysqldump is an effective tool to backup MySQL database. It creates a *.sql file with DROP table, CREATE table and INSERT into sql-statements of the source database. To restore the database,  execute the *.sql file on destination database. 1. Backup a single database # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql e.g. mysqldump -u root -prium mydatabase > mydumpfile.sql The sugarcrm.sql will contain drop table, create table and insert command for all the tables in the sugarcrm database. Following is a partial output of sugarcrm.sql, showing the dump information of accounts_contacts table: -- -- Table structure for table `accounts_contacts` -- DROP TABLE IF EXISTS `accounts_contacts`; SET @saved_cs_client     = @@character_set_client; SET character_set_client = utf8; CREATE TABLE `accounts_contacts` ( `id` varchar(36) NOT NULL, `contact_id` varchar(36) default NULL, `account_id` varchar(36) default NULL, `date_modified` ...