XAMPP (Windows) backup MySQL Database Automatically - php

I am trying to create a batch file in Windows to backup a MySQL Database, i have tried this:
C:\xampp\MySQL\bin\MySQLDump –u root –p database_name –result-file=”C:\Users\Administrator\Desktop\MySQLDump.sql”
but i get an error saying:
Got error: 1044: Access Denied for user ``#`localhost` to database `?u` when selecting the database

The solution to this problem/error was to use one of these mysqldump commands:
mysqldump --opt --lock-tables=false -u USER -p DBNAME > dump.sql
mysqldump --opt --single-transaction -u USER -p DBNAME > dump.sql
http://alvinalexander.com/mysql/mysql-error-1044-access-denied-for-user-using-lock-tables

Try this, it worked for me.
Don't forget to replace values inside {} as you need
C:\xampp\mysql\bin\mysqldump.exe -u{username} -p{passwrod} database > {/backuppath}.sql
Completed guide can be found at here:
https://www.tectut.com/2016/04/automatically-backup-mysql-databases-on-windows/

Related

How to get daily backup mysql database on godday hosting based on cronjob

i have issue to daily backup for mysql database.
export only all tables with data but not mysql function and stored procedure.
how to get full database backup?
I have use this cronjob.
mysqldump –opt -Q -h [myhost] -u myusername –p"*****" ebooklibrary > /fullpath.../_db_backups/openelibrary.sql
Add the "--routines" option, which is off by default in the query. This should give you the desired result. I hope this helps.
Read more here.
mysqldump --routines –opt -Q -h [myhost] -u myusername –p"*****" ebooklibrary > /fullpath.../_db_backups/openelibrary.sql

Mysqldump - How to restore a single table from this file?

I need to restore just a single table in my database.
I have a .sql file that has all the info I need for one table but the rest would overwrite important information for other tables.
Instead of using the solution here - using a tool I've never heard of, I figured it would be more sure fire to do it manually.
Unfortunately, the MySqlDump generated a GIANT insert line too long to paste into mysql command line...
What should I do?
Should I use sed like the link above describes?
Or could I copy paste the commands for that specific table from the mysqldump.sql into a new .sql file then call:
mysql -u root -p -h localhost < copyPasteFile.sql
u can try it
mysql -u root -p databasename -h localhost < copyPasteFile.sql
mysql -uuser -ppassword -e "create database temporary"
mysql -uuser -ppassword temporary < copyPasteFile.sql
mysqldump -uuser -ppassword temporary yourtable > onlythattable.sql
mysql -uuser -ppassword therealdb < onlythattable.sql
mysql -uuser -ppassword -e "drop database temporary"
make sure that copyPasteFile.sql does not have a "use somedatabase;" if it was exported with phpmyadmin, it probably has that, if it was exported with mysqldump it wont.
I am not sure if its the best way but I just spin up a new schema and restore the backup in to it, Dump the data I need and import that in to the production database.
I use the MYSQL work bench which makes it easier but the below steps can probably be reproduced at the command line
Create new MYSQL Schema
Import self-contained backup
Set "Target Schema" to the new empty database (.sql Dump must not contain schema creation code)
Restore backup
Dump table to csv and import it in to the production live database
Delete Restore Schema
To restore to a schema at the command line it looks like you use:
mysql -u <user name> -p <password> <database name> < sqlfilename.sql

Phpmyadmin "Error in processing request" when export table - Error code 500

I'm trying to use PhpMyAdmin v. 4.5.3.1 to access a DB on a localhost and export a table but it is not working.
I can access the DB, insert, search, etc. but when I click on "Export" tab it gives me this message:
I don't have this issue with PhpMyAdmin 4.2.6 using the same WAMP....
Does anyone knows how to fix it?
Thank you!
I think you should use mysqldump instead, when exporting data. From the command line:
mysqldump -uMYSQL-USER -h server -pMYSQL-USER database_name > /path-to-export
Or from a script:
$command = "mysqldump -uMYSQL-USER -h server -pMYSQL-USER database_name > /path-to-export/file.sql";
exec($command, $output, $return_var);
This can easily be automated.
You could fix this error by increasing memory limit to your requirement and restart httpd/apache service. I fixed it sometimes by increasing memory_limit. But now i prefer to use terminal commands only to handle it. Its better to always get habitual using terminal commands for doing such big operations in mysql. You get speed and more control over it as you are not dependent upon GUI based systems.
Use mysqldump in terminal to export data:
mysqldump -u root -p db_name > /home/dump.sql
Use mysqldump in terminal to export only schema without data:
mysqldump -u root -p db_name --no-data > /home/dump.sql

How to restore mysql from backup?

I have got alldatabase.sql file
How I can restore data with it?
My console comand is not working:
mysqldump -u root -p < alldatabase.sql
I must to create database first, but all database in my one file. What I must to do?
You use mysqldump to take a snapshot, but you restore using the mysql command
mysql -u root -p < alldatabase.sql

mysqldump to backup database from linux to windows server

I have a mysql server on a linux box (192.168.1.20) which has database named "retail". I want to create an automatic way to do a backup on windows server (192.168.1.30).
What is the best way to run the following code to do so :
mysqldump -h 192.168.1.20 -u root -p Retail > C:\Retail_Initiative\backup_20110315.sql
Any kind of help will be greatly appreciated.
How about creating a bat file with:
/START /WAIT mysqldump -uUSERNAME -pPASSWORD -h192.168.1.20 retail > path_to_dump_file
/START /WAIT mysql -uUSERNAME -pPASSWORD -h192.168.1.30 -e "DROP DATABASE retail; CREATE DATABASE retail;"
/START /WAIT mysql -uUSERNAME -pPASSWORD -h192.168.1.30 retail < path_to_dump_file
That should do it.

Categories