473,549 Members | 2,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sheduled mysqldump via windows bat file

I want to make a scheduled task in windows to do a mysqldump. Someone gave
me this .bat to run but I'm not able to get it to work.

REM @echo off

for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i

for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i
for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i
for /f %%i in ('time /t') do set DATE_TIME=%%i
for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i
C:\Program Files\MySQL\MyS QL Server 4.1\bin
mysqldump -u user -p'pass' dbname >C:\DATE_DAY%_% DATE_TIME%_data base.sql

When I run this script it doesn't work. All I get is a blank .sql file in
the output directory.
Can someone help me with this?
Mar 22 '06 #1
6 30078
"Robert Blackwell" <me@email.com > wrote in message
news:CGiUf.1180 8$wD1.3719@trnd dc02...
C:\Program Files\MySQL\MyS QL Server 4.1\bin
mysqldump -u user -p'pass' dbname >C:\DATE_DAY%_% DATE_TIME%_data base.sql


I see the following four errors in the above line.

1. Missing a beginning % character before DATE_DAY. Variables should have a
% before and after the variable name.
2. Must enclose the path to the mysqldump program in double-quotes to ensure
it's treated as one argument.
3. Must use double-quotes around "pass", single-quotes don't seem to work
when I try it.
4. Missing a slash between bin and mysqldump.

So this line should be:

"C:\Program Files\MySQL\MyS QL Server 4.1\bin\mysqldu mp" -u user -p"pass"
dbname >C:\%DATE_DAY%_ %DATE_TIME%_dat abase.sql

(that's all one line, no linebreak in the middle)

Regards,
Bill K.
Mar 22 '06 #2
Okay, I didn't have the slash because I thought the next part being on a
second line would be okay.

I pasted the line you fixed and changed the un/pass obviously. The command
prompt flashed briefly when it ran and it did create a .sql file using the
name formatting, however, it is still an empty file. I've tried waiting a
couple of minutes refreshing now and then but the file does not increase in
size as it would if I was dumping from a program such as mysqlfront.

I'm certain my login information is correct too.
Mar 22 '06 #3
"Robert Blackwell" <me@email.com > wrote in message
news:_clUf.8676 $I7.3143@trnddc 03...
The command prompt flashed briefly when it ran and it did create a .sql
file using the name formatting, however, it is still an empty file.
You should open a "cmd" shell window and run the bat script by typing its
name. Then if it has any error messages in its output, you'll see them. If
you run the bat script by double-clicking the bat file, the command window
disappears too quickly; you may not see any errors it prints.

So do you actually have a database called "dbname" or is that something you
need to change, just like the username/password?
I've tried waiting a couple of minutes refreshing now and then but the
file does not increase in size as it would if I was dumping from a program
such as mysqlfront.


Once you get a prompt back (or the window closes), the bat script is
finished. There will not be any further output going into that file.

Regards,
Bill K.
Mar 25 '06 #4
I've been typing a substitue dummy name.
"C:\Program Files\MySQL\MyS QL Server 4.1\bin\mysqldu mp" -u
user-p"mypassword " test >"C:\Document s and Settings\Admini strator\My
Documents\backu p db's\"%DATE_DAY %_%DATE_TIME%_t est.sql

I think what I was missing is the quotes around the password. However, with
that fixed, this is what's dumped.
- MySQL dump 10.9
--
-- Host: localhost Database: test
-- ------------------------------------------------------
-- Server version 4.1.14-nt

/*!40101 SET @OLD_CHARACTER_ SET_CLIENT=@@CH ARACTER_SET_CLI ENT */;
/*!40101 SET @OLD_CHARACTER_ SET_RESULTS=@@C HARACTER_SET_RE SULTS */;
/*!40101 SET @OLD_COLLATION_ CONNECTION=@@CO LLATION_CONNECT ION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHE CKS=@@UNIQUE_CH ECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KE Y_CHECKS=@@FORE IGN_KEY_CHECKS,
FOREIGN_KEY_CHE CKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@ @SQL_MODE, SQL_MODE='NO_AU TO_VALUE_ON_ZER O' */;
/*!40111 SET @OLD_SQL_NOTES= @@SQL_NOTES, SQL_NOTES=0 */;
I was able to keep the command prompt open so I could see what exactly was
goign on and if there was an error at the end, and there was.
mysqldump: Got error: 1044: Access denied for user 'user'@'%' to database
'test' when using LOCK TABLES.
I didn't know I locked the tables... or how to for that matter. I think if
you can walk me through unlocking them the script should hopefully work.

Then I tried using the root user account and it did dump the file... but i'm
not sure if it dumped the whole thing.
I just created a brand new db from a dump that I had made a while ago.
Thedump I imported happend to be 46.5MB. Now, when I ran this batch file the
dump it made is only 21.2MB. Can there be that much fluctuation in a dump?

If I zip up the original dump it compresses to 6.73MB
If I zip the new dump, it compresses to 6.25MB
I'd rather not use the root user in my bat so it would be nice to figure out
what permission/locking is preventing me from dumping with my other users.
Mar 27 '06 #5
"Robert Blackwell" <me@email.com > wrote in message
news:kiZVf.5145 $VL2.5013@trndd c04...
mysqldump: Got error: 1044: Access denied for user 'user'@'%' to database
'test' when using LOCK TABLES.
I didn't know I locked the tables... or how to for that matter. I think if
you can walk me through unlocking them the script should hopefully work.
Locking tables is a normal part of the work done by mysqldump. The locking
is enabled by the "--lock-tables" option, which is implicit when using the
"--opt" option, which is the default. (How's that for convoluted?)

A user can lock tables only if he/she has been granted the LOCK TABLES
privilege. Apparently, the user you're using to do the mysqldump lacks this
privilege, if you're seeing an Access Denied error.
Then I tried using the root user account and it did dump the file...
The root user is has all privileges, so it won't get the Access Denied
error.
I just created a brand new db from a dump that I had made a while ago.
Thedump I imported happend to be 46.5MB. Now, when I ran this batch file
the dump it made is only 21.2MB. Can there be that much fluctuation in a
dump?
Yes, it is possible for the output of two mysqldumps of the same database to
vary greatly in size, depending on the options used when running the
commands (e.g. --complete-insert, --extended-insert, etc.).

But if you want to double-check the databases, restore the dump file to some
new test database, and do some SELECT COUNT(*) queries on the tables.
Compare these to similar queries on your original table. If the results are
different, you know something is wrong. If the results are the same, you
know at least that the same number of records were backed up and restored
(but not necessarily that the content is intact).
I'd rather not use the root user in my bat so it would be nice to figure
out what permission/locking is preventing me from dumping with my other
users.


Yes, you can grant the right privileges as root:

mysql> use mysql;
mysql> GRANT SELECT, LOCK TABLES ON *.* TO 'user'@'%' IDENTIFIED BY
'password';

Regards,
Bill K.
Mar 28 '06 #6
Everything seems to hummin a long just fine now. Thanks a lot!
Mar 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2602
by: Mangina | last post by:
Hello all. Can anyone see why this snippet of code isnt dumping the databases using mysqldump ? All the credentials are correct (changed for the purpose of this post). $host = "localhost"; $user = "root"; $pass = "password"; $database = "database"; $dbname = array ("1","2","3","4","5");
3
3582
by: bobb | last post by:
Here's the syntax, I've never been able to do this. I'm SURE it'll help someone.!!! mysqldump -hhost -uuser -ppassword -c -t -wfield=value (don't forget quotes if string) database table > optionaltextfile.sql bobb
0
493
by: Thiko | last post by:
Hi We currently use mysqldump to dump all our db's in quick mode to one file, backup.sql. This file has come quite large. mysqldump -Aq -u root > /MySQL/backup/backup.sql I would now like to split the mysqldump so that the output comprises of several files of less than 2 gigabytes each. Does anyone know the mysqldump options that...
7
7401
by: Adam Smith | last post by:
Hope this is the right news group!! I did a server upgrade and at the same time did a mysql update from 4.0.12 to Ver 12.22 Distrib 4.0.16 mach1# mysql --version mysql Ver 12.22 Distrib 4.0.16, for portbld-freebsd4.9 (i386) I attempted to restore the DB with
0
2254
by: mcstayinskool | last post by:
I'm trying to dump a bugzilla installation to a file, then restore it to a different database name (so as to test my db backup system). I use mysqldump to dump it to a file: # mysqldump -u root -p<passwd> (misc. options) bugs > bugs.sql Then try to restore it to an empty DB, "foobar" with this command # mysql -u root -p<passwd> foobar <...
1
4026
by: Dave Crypto | last post by:
Hi there, SUMMARY: 1) When I use phpadmin to export a large database, the file created on my local PC never containes all the tables and information. It seems to max out at about 10mb. 2) Will running mysqldump from command line on a live in-use DB (with one table containing 350,000 rows) pose any risks and have any large effect of...
1
4671
by: Greg.Harabedian | last post by:
I'll start off by saying I am using MySQL v4.0 and my question is...how do I get mysqldump to dump the actual binary values store in a blob? Here is an example: -- Create a test table create table dummy(col1 blob); -- Next insert a null ascii character (0) insert into dummy values (char(0)); -- To verify there is actually something there...
6
6152
by: Antoni | last post by:
Hello, I'm trying to make a daily database backup. When executing "mysqldump - uxxx -pxxx database /home/backup/ddbb.sql -q &" the httpd server gets blocked and my site is "offline" for 30 minutes. I also tried using mysqlhotcopy, but with no success since it fails with error: "DBD::mysql::db do failed: Not unique table/alias: 'comments' at...
7
4710
by: damezumari | last post by:
I use Windows XP and Apache. I am trying to backup a database on my local computer with the following php code: $dbname = 'ol'; $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $backupFile = $dbname .'-' .date("Y-m-d-H-i-s") . '.sql';
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.