Update my remote MySQL database with my local MySQL database - mysql

I have a local Perl script that does a lot of parsing of web pages and then successfully updates my local MySQL database (WAMP server). I now want to send this local data to my remote server, but remotely connecting to my database isn't allowed with my hosting company. Unfortunately I never thought of that problem.
So, I now need to find an automated way to update my remote server (every 15mins). I mistakenly thought I could just edit my Perl script with the details of the remote server.
I am aware that I could use CGI or PHP to do the parsing on the server, but I really want to keep the parsing local for now.
Summary:
Local MySQL database -> remote MySQL database every 15mins ??
Any ideas what I can do?
Thanks :-)

if replication is not an option but you can still establish an ssh connection from local box to remote box, then
run mysqldump to export data into a file http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_where
scp file to remote box
mysql -u username -p password database_name < dumpfile.sql

If your server does not accept connections to mysql remotely you can create a ssh tunnel. Then you can apply the replication solution proposed by matcheek.
Here is a hint: http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html

Based on the responses I've received, I think the answer to my original question is to stop using a cheap shared hosting company (no remote access to server, no cron jobs, etc) and start using a VPS hosting company. That will give me the freedom to remotely connect to my server, etc.
Thanks again to those who replied.

From how you described the problem replication seems to be the way to go
http://dev.mysql.com/doc/refman/4.1/en/replication-howto.html

Using a cron job could be another option. It would read file from your local machine and import data in the remote box.

I suggest the follwing:
On every local run, write the SQL statements (sans SELECT),
that you run against your copy of the DB also into a file
On your WAMP server create a small PHP script, gives back the oldest script from the first step (soem auth ofcourse)
On your remote server run a cronjob, that gets this from your local server and runs the SQL against the DB, then acknowledges it
On acknowledgement on your WAMP server, drop the file and give back the next one.
While this seems complicated, it allows for a restart after connectivity loss - something that I consider imposrtant.

Related

Routinely pull data from remote database to local

Is there a simpler approach to routinely keep a local MySQL database updated with data from a remote database? My setup needs me to run a local copy of the project in the office network to allow local email sending. But the emails link back to a live server. Also, the admin users need to access the project from the internet anywhere to compose the emails. Currently, my options are:
Connect local project to the remote database.
Export the remote database, clean the local database and then import the dump.
This is something I need to routinely do every week. I went with approach #1 but it takes a long time to pull data this way. So I am really wondering if I should do this in the long run?
On routine basis, just do the mysqldump export on remote server and then on local server do mysqldup import or mysql import.
mysqldump -u root-proot -h remote-server test > db%FileDate%.sql
And on local server, do the import
mysql -u root-proot -h local-server test < db%FileDate%.sql
You can use mysql incremental backup. Please refer below link.
https://www.percona.com/forums/questions-discussions/percona-xtrabackup/10772-[script]-automatic-backups-incremental-full-and-restore
https://dev.mysql.com/doc/mysql-enterprise-backup/8.0/en/mysqlbackup.incremental.html

Automate Putty To Do Daily Task

I am fairly new to putty, need your help guys I would repeatedly connect to a linux server using putty almost everyday then connect to one more linux sever from within previous linux server as it contains database, then login to mysql and take a database back up
I want to automate this process by creating a bat file as am on windows 7, i was able to login to putty and then to mysql, but console disappears after that
login to putty with username password
ssh to another server and login with username password
login to mysql then take a db back up using mysql dump
copy the db backup file to desktop
Thanks in advance
When your goal is making the backup, you do not need to automate Putty. You can make a unix script that will call mysql and make a backup. When that script works, you can add it to crontab (Unix scheduler), so it will run every day.
You need some more testing before crontab works well: your environment in an interactiv session will be different.
Edit: Did not answer the last part:
And 4. copy the db backup file to desktop
There are different ways for transporting the backup. You can have a mounted drive, shared directory, or use some transport protocol like rsync or scp. I can not tell which fits best in your situation.

Transfer MySQL database to remote server

How do I go about transferring a MySQL database from my localhost to a remote server? Can it only be done in a command prompt? Right now, I'm running MySQL 5.1 with a Command Line Prompt and Query Browser. In SQL Server, you just take the DB offline, copy the .mdf file over, and you're done, but it doesn't seem to be that simple. Thanks!
http://dev.mysql.com/doc/refman/5.0/en/copying-databases.html should be quite helpful.

Execute Shell command over MySql on remote host

Is it possible to login into a remote mysql machine and execute commands using 'system' on the remote machine.
I can log into the remote machine, but commands using: 'system' are executed at my local machine.
Thanks indeed!
I using mysql to connect from 'Host1' to 'Host2' using the command
mysql -uUsername -p data_base_name -h Host2
When I execute
'system hostname'
after I'm connected i get.
'Host1'
I cannot log into my remote host using ssh. I don't know why. I need to do some log analysis and the only option I have is to connect to that machine using mysql. I can connect to that machine! –
As far as I know, this is definitely not possible. It's far beyond the scope of mySQL, and there would be immense security implications if it were.
I don't think there is an alternative to getting SSH (or some other service that might help) running again.
Consider doing a select into outfile and writing script code into a place that will be executed on the server. For example, if mysql is running as root on the server, you be able to add something to the /etc/rc2.d which will get executed on the server during boot time.
Alternatively, if there is a file which is used as a source for scheduling tasks you may be able to overwrite that again using "select into outfile."
system runs local commands on your box. If you need to do anything with logs, either contact your hoster, to provide a way to download them or access them.

Replication server setup for mysql using phpmyadmin Cpanel

I am hosting my website on a shared server, with a mysql database which I can access it using phpmyadmin only. Can we setup replication mechanism to replicate my DB to my local server periodically?
something like periodically it should dump the data from my live server to my local server or atleast create a dump file.
Thanks,
You can use this URL: http://username:password#website:2082/getsqlbackup/website…database.gz to get a gzipped copy of your databse. username and password are as they say, and 2082 is whatever port you use.
You can use wget in a batch file to get it automatically.