Help. Need to start mysql from a bash script

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

Help. Need to start mysql from a bash script

Postby caltuna » 06. May 2009 01:14

I need to be able to start mysql from a bash script so that I can then reload a database with a backup (dump) file. This is done several times a day via cronx (a Mac application to run scripts.)

I can do this in MAMP, but not in XAMPP.

XAMPP is configured to run as root!

/Applications/XAMPP/xamppfiles/xampp startmysql
You need to start XAMPP as root!

I thought maybe I could put sudo and my password in a script, but I can't figure a way to do it.
Is there so way to get around this? Maybe a chmod to change permissions or what? If I can't run the script, XAMPP is a non-starter and I'm back to MAMP.

Thanks,

Al
caltuna
 
Posts: 111
Joined: 05. May 2009 16:35

Re: Help. Need to start mysql from a bash script

Postby Wiedmann » 06. May 2009 07:40

What's your problem with running cronjobs as root?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Help. Need to start mysql from a bash script

Postby caltuna » 06. May 2009 07:48

Wiedmann wrote:What's your problem with running cronjobs as root?


You are right. I didn't know that you could run a script as root via Cronix. That solved ALL the problems. Here is the script in case you are interested. I'm not sure why I need the 'sleep' command but it does not work without it. Anyone know? Anyway this works great.

Code: Select all
#!/bin/sh
cd /users/al/documents/mysugar
/Applications/XAMPP/xamppfiles/xampp startmysql >/dev/null
sleep 30
/Applications/XAMPP/xamppfiles/bin/mysql -u root -h localhost sugar < /users/al/documents/mysugar/sugar.bak
/Applications/XAMPP/xamppfiles/xampp stopmysql  >/dev/null


Also, I was able to zip my Sugarcrm code from MAMP's htdocs (it's about 10,000 php files), paste it to XMAMP's htdocs and unzip. You then have to chmod the folder to 777 and increase the memory_max in the php.ini.

Thanks.
caltuna
 
Posts: 111
Joined: 05. May 2009 16:35

Re: Help. Need to start mysql from a bash script

Postby make-fun » 06. May 2009 07:54

Only got it for Linux, but may work for you too.

Starting MySQL on Linux
Code: Select all
/etc/init.d/mysql start


Create a SQL BackUp
Code: Select all
# As a password should be set and a diffrent host may be used,
# change the following values in the line "SQL_Statment"
# +++ HOST     = localhost   (most likely)
# +++ User       = root      (most likely)
# +++ Password = 12345678
SQL_Statment="-h localhost -u root -12345678 -c --add-drop-table --add-locks --all --quick --lock-tables --all-databases"
mysqldump $SQL_Statment > sqlDump.sql
This will dump all all-databases into one SQL file.

Load a SQL BackUp
Code: Select all
mysql -h localhost -u root -12345678<sqlDump.sql


Maybe this will get you started on the Mac — let me know if it works

Cheers
make-fun
 
Posts: 31
Joined: 11. March 2009 04:21

Re: Help. Need to start mysql from a bash script

Postby caltuna » 06. May 2009 15:55

I do something similar. On my server I run this script each hour which dumps my sugar database, zips it and sends it to MobileMe for back up. In the previous script which I run as root via Cronix, I download it to my local Mac, start XAMPP and it reloads the local copy of sugarCRM. In this way I have four copies of the file... the production version, a zipped version on the server, a zipped version on MobileMe, and a local version. I only use the local version in case I lose my internet connection. If that happens and I have to make changes to local version, I use phpMyAdmin to manually dump the local version re-load the production version. Happens maybe once a year.

I can't tell you how long it took me to figure out how to use cadaver. PITA. You have to have the password and user stuff in a separate file which you don't see in this script... cadaver knows the name and reads it. Why Apple had to use webdav and not the FTP protocol is beyond me!

Code: Select all
#!/bin/sh

#create a date-time suffix for new fle.
b=$(date  +"%m%d%y%H%M%S")

#dump sugar to backup and zip it.
/usr/local/bin/mysqldump -eqf --add-drop-table -h localhost -u xxxxxxx --password=xxxx sugar2 | gzip > dbsugar_$b.bak.gz

#save it to a folder on server after deleting whatever is in it.
rm /usr/home/xxx/backupsugar/backup_current_sugar/*.bak.gz
cp /usr/home/xxx/backupsugar/dbsugar_$b.bak.gz /usr/home/xxx/backupsugar/backup_current_sugar/

#send a copy of zip file to MobileMe using cadaver
#get name of file from folder. (not sure why this is done... has something to do in passing name of file to the lame cadaver program. FTP is better!)

filename=$(ls /usr/home/xxx/backupsugar/backup_current_sugar/*)

#code for sending this to Apple server (there is a hidden file with password and user name that is necessary. See man page for cadaver)
/usr/local/bin/cadaver -t idisk.mac.com/xxx/yyyzzzr << EOF > /dev/null
delete *
put $filename
quit
EOF


I hope this helps anyone who wants to keep multiple copies of a database. I run my insurance agency (link below) on SugarCRM so I can't be too careful about backing up. (I also burn a cd of the zip file once a day... just in case Apple's MobileMe, my dedicated server at my ISP (PairNetworks), and my local Mac Mini machine all get wiped out at the same time!)

Al
http://www.insol123.com
caltuna
 
Posts: 111
Joined: 05. May 2009 16:35


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 19 guests