MySQL Automate backups - php

I am trying to automate the backups of our MySQL databases.
The databases are hosted on shared servers, and can be restarted at anytime, which mean CRON jobs won't be persistent (according to support at my web hosts).
I am currently running the jobs manually via MySQL Workbench at given intervals.
I am trying to automate this process, but I cannot fathom how to do it. There seems to be no options in MySQL Workbench, and Google seems to yield nothing.
I have attempted to run mysqldump on my local machine, with the view to creating some kind of script to do this from my machine. But I get an error - mysqldump: Got error: 2049: Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled) when trying to connect - which I can't seem to disable at the server end or override at my end.
Any advice?

The standard automatic backup for MySQL is the socalled "MySQL Enterprise Backup" (MEB). MySQL Workbench works with MEB, but as the name indicates this solution is only available for MySQL enterprise servers.
Another solution would be to run a cron job on the target server (using mysqldump). Missed jobs will be executed after the system is up again, so this is a reliable solution too.
If you cannot install a cron job on the target machine then you will have no choice but to manually trigger the backup either with MySQL Workbench or on the commandline.

Related

Forseeable issues with running phpMyadmin MySql and MySQL root installed on my machine

I installed MySQL on my machine (Desktop, Windows 10) and created an application that gets data from the database and displays it on the application. The application is not important at this time.
I then installed Xampp, with Apache,Mysql, and phpMyadmin. I am trying to learn how to take my database onto the web. The issue/problem I am having is that in order to access the phpMyadmin website I need to close my Mysql connection on my machine via the Task Manager in order to connect to phpMyadmin. Then in order to connect to the MySql on my machine so my application can access the database I need to Stop the MySql connection via the Xampp application.
This is just for development, for now, it is not for a project. Is it okay to keep opening and closing the Mysql connections like this?
I do believe the error is caused because they (machine MySQL and phpMyadmin MySQL) both run on the same port of 3306. Is there also a way to solve this?

How to connect to SQLYog localhost or otherwise

I am new to working with servers, and am not able to use SQLYog because it is not able to connect to any server. When I try to use the default values to connect to MySQL (localhost, root, port 3306), I get "Error No. 2003: Can't connect to MySQL server on 'localhost' (0).
Is there something I am missing or that I have to correct? I am just trying to create a database.
SQLyog is just one way to connect to a MySQL database and interact with it. Other popular methods include MySQL Workbench, Navicat, phpMyAdmin, and others.
Before you can use any of these, you have to first make sure your MySQL server is running and accepting connections. You didn't mention (or tag) whether you are running MySQL on your local machine, or what operating system you are using.
A couple of the most common development environments are LAMP or WAMP, for "Linux, Apache, MySQL, php" or "Windows, Apache, MySQL, php" respectively. Since you tagged your question php, I'll assume one of these is appropriate. (For example you're using SQLyog on Windows but your MySQL server is on Linux.) (I'll presume Ubuntu for Linux examples.)
On the machine you've installed MySQL (along with any other components), you should be able to determine its running state by looking at your process list (ps aux in Ubuntu, tasklist or Task Manager (GUI) in Windows).
You're looking for mysqld (Linux) or mysqld.exe (Windows). If the process isn't running, you need to start it (Linux/Windows). If you're using WampServer (a popular Windows all-in-one package), for example, you can also look in your Windows Services for "wampmysqld" or "wampmysqld64" and start the service there.
If you can't get the process to start, you may have a configuration error. If the process is running, you may need to check the configuration any way to determine what port it is running on, if it's not the standard 3306.
The configuration file name and location can vary by system and package, but generally it will be called "my.cnf" (Linux) or "my.ini" (Windows). Check your documentation for help on the specific path.
Once you've got the service running, you should be able to connect!
This is the default SQLyog connection dialog (at least in my slightly older version). The defaults assume you are running your MySQL server on your local machine (localhost), that you have a user "root" with no password, and the default port 3306 is used.
You'll need to change any of this information that differs on your particular installation.
Be aware that if you're trying to connect to an instance of MySQL on another machine, a firewall may be blocking a port.
These steps should hopefully get you on the right track.

running the same database both local and online in mysql

I am creating a software for my client in PHP and MySql, The software will be running in the local network, the software should also run in online that is all the data should be viewed online, i would like to know is there a way to update the mysql database from local to online whenever the internet is connected, if the internet is not connected all the data will be stored in local mysql server. they wont be adding any data in the online server and they will only view the contents. Kindly help me in this
It sounds like you are looking for a way to have a read-only, "online" (assuming WAN) MySQL server which is updated from a read-write, "offline" (LAN) MySQL Server which is updated by your users.
If that's the case, you may want to consider a Master/Slave MySQL Replication configuration:
http://www.rackspace.com/knowledge_center/article/mysql-replication-masterslave
you can run a cron job in your local server which monitor and upload data to online server when internet is available. You need to track (set a status) which data is uploaded which not for synchronization
Setup replication between your mysql databases. The local network database would be the slave and the web server would be the master.
See http://dev.mysql.com/doc/refman/5.5/en/replication-howto.html for setting up replication.
I would suggest you setup master/slave replication.
I would make the local server the master and the internet server the slave.
However, if you are using a common shared hosting service, I am not too sure if you have permission to setup such DB replication structure.
Tryhttps://www.digitalocean.com/community/articles/how-to-set-up-master-slave-replication-in-mysql. However, with the mysql versions pre 5.6 (I think) you can't delay the replication from a predefined interval. However, http://alexalexander.blogspot.com/2013/03/mysql-slave-delay-how-to.html suggests using something called a percona tool kit. I haven't used it though.

Connecting to external MySQL DB from a web server not running MySQL

While I've been working with MySQL for years, this is the first time I've run across this very newbie-esq issue. Due to a client demand, I must host their website files (PHP) on a IIS server that is not running MySQL (instead, they are running MSSQL). However, I have developed the site using a MySQL database which is located on an external host (Rackspace Cloud). Obviously, my mysql_connect function is now bombing because MySQL is not running on localhost.
Question: Is it even possible to hit an external MySQL database if localhost is not running MySQL?
Apologies for the rookie question, and many thanks in advance.
* To clarify, I know how to connect to a remote MySQL server, but it is the fact that my IIS web server is not running ANY form of MySQL (neither server nor client) that is giving me trouble. Put another way, phpinfo() does not return anything about MySQL. *
Yes, you can use a MySQL database that's not on the same machine as Apache+PHP.
Basically, you'll connect from PHP to MySQL via a network connection -- TCP-based, I suppose ; which means :
MySQL must be configured to listen to, and accept connections on the network interface
Which means configuring MySQL to do that
And given the required privileges to your MySQL user, so he can connect from a remote server
And PHP must be able to connect to the server hosting MySQL.
Note, though, that habing MySQL on a server that's far away might not be great for performances : each SQL query will have to go through the network, and this could take some time...
If phpinfo is not returning anything about MySQL you need to install the MySQL plugin for PHP, easiest way to do that probably is to just upgrade PHP to the latest version. If not there is a .DLL file that you will need.
http://www.php.net/manual/en/mysql.installation.php
you will need to install the mysql extensions. this link should help: http://php.net/manual/en/install.windows.extensions.php
The MySQL server has nothing to do with PHP itself. What "mysql support" in PHP means is that it's been compiled with (or has a module loaded) that implements the MySQL client interface. For windows, it'd be 'mysql.dll', and on Unix-ish systems it'd be 'mysql.so'. Once those are loaded, then the various MySQL intefaces (mysql_xxx(), mysqli_xxx(), PDO, MDB2, etc...) will be able to access any MySQL server anywhere, as long as you have the proper connection string.

How to download a live MySQL db into a local test db on demand, without SSH?

I have a fairly small MySQL database (a Textpattern install) on a server that I do not have SSH access to (I have FTP access only). I need to regularly download the live database to my local dev server on demand; i.e., I would like to either run a script and/or have a cron job running. What are some good ways of doing this?
Some points to note:
Live server is running Linux, Apache 2.2, PHP 5.2 and MySQL 4.1
Local server is running the same (so using PHP is an option), but the OS is Windows
Local server has Ruby on it (so using Ruby is a valid option)
The live MySQL db can accept remote connections from different IPs
I cannot enable replication on the remote server
Update: I've accepted BlaM's answer; it is beautifully simple. Can't believe I didn't think of that. There was one problem, though: I wanted to automate the process, but the proposed solution prompts the user for a password. Here is a slightly modified version of the mysqldump command that passes in the password:
mysqldump -u USER --password=MYPASSWORD DATABASE_TO_DUMP -h HOST > backup.sql
Since you can access your database remotely, you can use mysqldump from your windows machine to fetch the remote database. From commandline:
cd "into mysql directory"
mysqldump -u USERNAME -p -h YOUR_HOST_IP DATABASE_TO_MIRROR >c:\backup\database.sql
The program will ask you for the database password and then generate a file c:\backup\database.sql that you can run on your windows machine to insert the data.
With a small database that should be fairly fast.
Here's what I use. This dumps the database from the live server while uploads it to the local server.
mysqldump -hlive_server_addresss -ulive_server_user -plive_server_password --opt --compress live_server_db | mysql -ulocal_server_user -plocal_server_password local_server_db
You can run this from a bat file. You can ever use a scheduled task.
Is MySQL replication an option? You could even turn it on and off if you didn't want it constantly replicating.
This was a good article on replication.
I would create a (Ruby) script to do a SELECT * FROM ... on all the databases on the server and then do a DROP DATABASE ... followed by a series of new INSERTs on the local copy. You can do a SHOW DATABASES query to list the databases dynamically. Now, this assumes that the table structure doesn't change, but if you want to support table changes also you could add a SHOW CREATE TABLE ... query and a corresponding CREATE TABLE statement for each table in each database. To get a list of all the tables in a database you do a SHOW TABLES query.
Once you have the script you can set it up as a scheduled job to run as often as you need.
#Mark Biek
Is MySQL replication an option? You could even turn it on and off if you didn't want it constantly replicating.
Thanks for the suggestion, but I cannot enable replication on the server. It is a shared server with very little room for maneuver. I've updated the question to note this.
Depending on how often you need to copy down live data and how quickly you need to do it, installing phpMyAdmin on both machines might be an option. You can export and import DBs, but you'd have to do it manually. If it's a small DB (and it sounds like it is), and you don't need live data copied over too often, it might work well for what you need.

Categories