I am new to MySQL so please have some patience...
I have been tasked with refreshing a particular UAT Schema, however when I've restored the Schema not all of the tables are present.
Details are as follows; -
The size of the schema is 75Gb
The six largest tables contain 2.3Gb, 3.3Gb, 4.8Gb, 13.6Gb, 15.2Gb and 33.8Gb of data.
The method for the backup is a Windows Server scheduled task running a .bat file, the command for the backup is:
REM BH 26/05/19
#echo on
net use z: /delete /y
Net use z: "\\THE NETWORK SHARE NAME"
set mydate=%date:/=%
set mytime=%time::=%
set mytimestamp=%mydate: =_%_%mytime:.=_%
set dbname=schemaname
set filename="E:\Backup\%dbname%-%mytimestamp%.sql"
set filename2="E:\Backup\%dbname%-%mytimestamp%.tz"
echo %filename%
cd "E:\Backup"
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe" %dbname% --user=??? --password=??? --host=localhost --port=3306 --quick --lock-tables=false --result-file=%filename% --default-character-set=utf8 --single-transaction=TRUE
I am using MySQL Workbench to perform the restore, the restore completes but there are over a 150 tables missing.
Note the following: -
Account running the backups has access to all areas of MySQL
New Dump files are created every three hours
I have been using the latest dump files
Many Thanks
Related
I am moving one database from one computer to another computer.
I have copied the folder from Xampp > Mysql >Data > 'Database named folder' and placed in same location in new computer.
Now I am trying to access the tables of that database from new computer using PHPMYADMIN from browser and I am getting this error :
#1932 - Table 'recoverydata.assignfeedback_editpdf_quick' doesn't exist in engine
Is there any more file that I need to copy? Or what's the solution?
Using Command Line Windows:
Exporting the database
Open up a Windows command prompt.
Change the directory to the following to access the mysqldump utility.
cd \bin
Create a dump of your current mysql database or table (do not include the bracket symbols [ ] in your commands).
Run the mysqldump.exe program using the following arguments:
mysqldump.exe –e –u[username] -p[password] -h[hostname] [database name] > C:\[filename].sql
If you supplied all the arguments properly, the program will connect to your current mysql server and create a dump of your whole database in the directory you specified in your C:\ directory. There is no message that will indicate the dump has been completed, the text cursor will simply move to the next line.
Here is an example of the command line syntax:
Importing The Database :
Go to the directory that the mysql client utility is located.
cd C:\Program Files\MySQL\MySQL Server 5.5\bin
Import the dump of your database or table.
Run the mysql.exe program using the following arguments.
mysql –u[user name] -p[password] -h[hostname] [database name] < C:\[filename].sql
I have a MySQL database that I want to daily backup to my Dropbox folder on my Windows PC.
How can I do that automatically from Windows 7?
One of the simplest ways to backup a mysql database is by creating a dump file. And that is what mysqldump is for. Please read the documentation for mysqldump.
In its simplest syntax, you can create a dump with the following command:
mysqldump [connection parameters] database_name > dump_file.sql
where the [connection parameters] are those you need to connect your local client to the MySQL server where the database resides.
mysqldump will create a dump file: a plain text file which contains the SQL instructions needed to create and populate the tables of a database. The > character will redirect the output of mysqldump to a file (in this example, dump_file.sql). You can, of course, compress this file to make it more easy to handle.
You can move that file wherever you want.
To restore a dump file:
Create an empty database (let's say restore) in the destination server
Load the dump:
mysql [connection parameters] restore < dump_file.sql
There are, of course, some other "switches" you can use with mysqldump. I frequently use these:
-d: this wil tell mysqldump to create an "empty" backup: the tables and views will be exported, but without data (useful if all you want is a database "template")
-R: include the stored routines (procedures and functions) in the dump file
--delayed-insert: uses insert delayed instead of insert for populating tables
--disable-keys: Encloses the insert statements for each table between alter table ... disable keys and alter table ... enable keys; this can make inserts faster
You can include the mysqldump command and any other compression and copy / move command in a batch file.
My solution to extract a backup and push it onto Dropbox is as below.
A sample of Ubuntu batch file can be downloaded here.
In brief
Prepare a batch script backup.sh
Run backup.sh to create a backup version e.g. backup.sql
Copy backup.sql to Dropbox folder
Schedule Ubuntu/Windows task to run backup.sh task e.g. every day at night
Detail steps
All about backing up and restoring an MySQL database can be found here.
Back up to compressed file
mysqldump -u [uname] -p [dbname] | gzip -9 > [backupfile.sql.gz]
How to remote from Windows to execute the 'backup' command can be found here.
plink.exe -ssh -pw -i "Path\to\private-key\key.ppk" -noagent username#server-ip
How to bring the file to Dropbox can be found here
Create a app
https://www2.dropbox.com/developers/apps
Add an app and choose Dropbox API App. Note the created app key and app secret
Install Dropbox API in Ubuntu; use app key and app secret above
$ wget https://raw.github.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh
$ chmod +x dropbox_uploader.sh
Follow the instruction to authorize access for the app e.g.
http://www2.dropbox.com/1/oauth/authorize?oauth_token=XXXXXXX
Test the app if it is working right - should be ok
$ ./dropbox_uploader.sh info
The app is created and a folder associating with it is YourDropbox\Apps\<app name>
Commands to use
List files
$ ./dropbox_uploader.sh list
Upload file
$ ./dropbox_uploader.sh upload <filename> <dropbox location>
e.g.
$ ./dropbox_uploader.sh upload backup.sql .
This will store file backup.sql to YourDropbox\Apps\<app name>\backup.sql
Done
How to schedule a Ubuntu can be view here using crontab
Call command
sudo crontab -e
Insert a line to run backup.sh script everyday as below
0 0 * * * /home/userName/pathTo/backup.sh
Explaination:
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command
Or simply we can use
#daily /home/userName/pathTo/backup.sh
Note:
To mornitor crontab tasks, here is a very good guide.
I want to copy my mysql database from my computer to another computer. How can I do this?
How to copy Mysql database from one Computer to another / backup database using mysqldump
We can transfer a MySQL database from one PC to another PC using
mysqldump command.
We have to create dump file of database to transfer database from
one PC to another PC.
MySQL database is not portable database i.e. we cannot transfer it
from one PC to another PC by copying and pasting it.
We can use following method to transfer database.
Creating a dumpfile from database/ Taking backup of MySQL database:
Open command prompt.
Execute following commands to change directory
>c: “press enter”
>cd program files/MySQL/MySQL Server 5.1/ bin “press enter”
>mysqldump -u root -p database_name > database_name.sql “press enter”
Enter password: password of MySQL
Copy sql file and paste it in PC where you want to transfer database.
2. Dumping sql file into database:-
- Open MySQL command line client command prompt.
- Execute following command to create database.
create database database_name;
“press enter” Database name is must as that of your database_name.
Copy that sql file into location “c:/program files/MySQL/MySQL Server 5.1/bin”
*- Now open command prompt and execute following commands.*
>C: “press enter”
>cd program files/MySQL/MySQL Server5.1/bin “press enter”
>mysql –u root –p database_name < database_name.sql “press enter”
Your database is created on PC.
Now in MySQL command prompt check your database.
Another one:1
This best and the easy way is to use a db tools(SQLyog)
http://www.webyog.com/product/downloads
With this tools you can connect the 2 databases servers and just copy one database on server a to server b.
For more info
http://faq.webyog.com/content/12/32/en/mysql-5-objects-are-greyed-out-in-copy-db-to-other-host-dialogue.html
Another one:2
For a database named "lbry", try this:
mysqldump -u root -p lbry > dump-lbry.sql
Create a database of the same name ("lbry" in this example) on the computer to which you wish to copy the database contents
Then import it:
mysql -u root -p lbry < dump-lbry.sql
You can do by this process step-by-step using MySQL WorkBench.
Install MySQL Workbench
Connect to existing Database
Go to Navigator -> Management -> Data Export.
(this will dump queries of tables one by one in a separate folder, Workbench uses the same folder to import)
Create Database on target PC.
Connect to Target Database (would consist of 0 tables in DB)
Go to Navigator -> Management -> Data Import/Restore.
(this will use the dump folder and create tables in your target Database).
Hope this helps.
The only SAFE way to copy databases from one machine to another is to first quiesce the database (make sure no clients are modifying it), then use the mysqldump command to create a text representation of your schema and the contents of your tables. Then copy that text file over to the other machine and read it in by specifying it as the input to the mysql command.
Attempting to copy the actual mysql data directories over is asking for trouble, since they are dependent on the architecture of the machine that mysql is running on and likely on the version of mysql and whatever storage engine is in use.
This tutorial is in Ubuntu but will work on Redhat, Centos, Fedora, Suse
We can dump database, transfer it to another server, and restore it
It will show how to take care of things like modified credentials as a result and moving debain.cnf file
4 dump restore will slow down the serverHow it works
4.1 Run mysqldump on source server:this builds a MySQL executable script for the destination server.
During this time the MySQL server will queue queries
4.2 Copy dump file to the destination server
4.3 Empty destination server
4.4 Execute dump file on the destintion server
Server A(Source Server)
Server B (Destination Server)
Case 1:Server A
root#source$ mysql --defaults-file=/etc/mysql/debain.cnf
mysql>show databases;
mysql>use testdb;(The database to dump)
mysql>show tables;(To Check the tables)
mysql>^c
-- now dump the databses
root#surce$ mysql --defaults-file=/etc/mysql/debain.cnf --all-databses | gzip -c > dump.sql.gz
root#surce$ gzip -dc dump.sql.gz
To copy the files create a ssh key on the source server
root#surce$ ssh-keygen
root#surce$ cat /root/.ssh/id_rsa.pub
select and copy all the ssh key string
root#surce$ scp dump.sql.gz ubuntu#destination:
goto destination server
last step copy the contents of debain.cnf file
root#surce$ cat /etc/mysql/debain.cnf
[client]
host = localhost
user = debain-sys-maint
password = mysecret
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debain-sys-maint
password = mysecret
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
select all and copy this file to detination server.
Note: The sockey path can be different in your machine .use locate command to find the exact path
Case 2. Server B
drop all databses
root#destination$ echo show databases | mysql --defaults-file=/etc/mysql/debian.cnf --skip-column-names | awk '{print "drop database "$1";"}'
if this command doesnot drop databses use it with -force option
root#destination$ echo show databases | mysql --defaults-file=/etc/mysql/debian.cnf --skip-column-names | awk '{print "drop database "$1";"}' | mysql --defaults-file=/etc/mysql/debian.cnf -f
copy the ssh key on the destination server
root#destination$ echo "paste the key here" >> /home/ubuntu/.ssh/authorised_keys
goto source Server and use scp command to move the dump on the destination server
(inject the file)
root#destination$ gzip -dc /home/ubuntu/dump.sql.gz | mysql --defaults-file=/etc/mysql/debain.cnf
root#destination$ > /etc/mysql/debain.cnf
root#destination$ nano /etc/mysql/debain.cnf
paste the contents of .cnf file from source server here and save the file
:x
root#destination$ mysql --defaults-file= /etc/mysql/debain.cnf
if you get the mysql prompt then everything should be working file
mysql>
I was able to restore a backup that was shared with me following this thread, specifically #jmail's answer, but, I thought that I could provide a bit more concise answer for future users. I received a dump file with a .sql extension, not a .dump extension as I would have expected.
I tried to place it in my project folder and restore it but I got error 22, referring to access privileges. I moved it to “c:/program files/MySQL/MySQL Server 5.1/bin” and then ran it by:
1) Starting MySQL in the command prompt.
2) Creating the new database that I wanted to restore to
3) Switching to the database
USE new_DB;
4) Running
source c:/program files/MySQL/MySQL Server 5.1/bin/backup.sql
I'm not sure how the backup.sql file was created but this worked for restoring it on my Windows 10 system.
mysqldump --databases dbname -hsource_server_ip -usource_server_userName -psource_server_passcode | mysql
-udest_server_user_name -pdest_server_user_passcode &
There are three general ways to invoke mysqldump:
shell> mysqldump [options] db_name [tbl_name ...]
shell> mysqldump [options] --databases db_name ...
shell> mysqldump [options] --all-databases
If you do not name any tables following db_name or if you use the --databases or --all-databases option, entire databases are dumped.
mysqldump does not dump the INFORMATION_SCHEMA database by default. MariaDB dumps the INFORMATION_SCHEMA if you name it explicitly on the command line, although currently you must also use the --skip-lock-tables option.
To see a list of the options your version of mysqldump supports, execute mysqldump --help.
I just summarize jmail's answer:
Database to SQL file at computer 1:
mysqldump --user <user name> --password <database> > <output file> for example mysqldump --user root --password movie > movie.sql
SQL file to database at computer 2:
mysql --user <user name> --password <database> < <output file> for example mysql --user root --password movie < movie.sql
I setup fresh xampp(latest version) and copy mysql/data folder from old xampp(little bit lower version).
When I am access my magento project database through phpmyadmin, i am shocked. Here only 19 tables listed.
I checked in mysql/data directory, database folder and files with tables name(*.frm) are exist.
Please let me know how can i get back my complete database?
PS: I am using window 7.
In Magento most of the tables are innodb (except for those 19 you found in your new installation). For innodb tables you cannot just copy the table files from the data folder. See this for more explanations.
If you cannot create a dump of the old db and restore it in your new xampp it may be lost.
When copying Magento Database, be sure to use "Single Transactions". Otherwise, it will cause issues.
this is how I do it using command line:
Dump existing table into a file:
mysqldump -u [YOUR USER] -p'[YOUR PASS]' --single-transaction --database [Your DB Name] > [FILE-NAME-TO-DUMP.sql]
Then copy the file to the server you want to create the database.
Create your database that you'll be using on the new server
Run the following
cat [FILE-NAME-TO-DUMP.sql] | grep -vi "^USE" | grep -vi "^CREATE DATABASE" | mysql -u [YOUR USER] -p'[YOUR PASS]' --database [Your DB Name]
Moving from an old Win2003 server to a new VM server (our choice Win or Linux)
if we go Linux would there be any problems converting the current tables?
Moving MySQL/Windows to same version of MySQL/Linux
You can mysqldump all the databases as follows:
C:\> mysqldump -uroot -p --routines --triggers --flush-privileges --all-databases > MySQLData.sql
Move MySQLData.sql to Linux box and run the reload
mysql -uroot -p < MySQLData.sql
Moving MySQL/Windows to higher version of MySQL/Linux
You can mysqldump all the databases EXCEPT THE mysql SCHEMA !!! Why?
MySQL has the grants for the user in a main table called mysql.user.
For each major release of MySQL, mysql.user has the following number of columns:
43 columns in MySQL 5.6
42 columns in MySQL 5.5
39 columns in MySQL 5.1
37 columns in MySQL 5.0
31 columns in MySQL 4.0/4.1
I have discussed mysql.user's column arrangement before
May 01, 2013 : Can I find out what version of MySQL from the data files?
Dec 24, 2012 : Backup and restore "mysql" database
Jun 13, 2012 : Fastest way to move a database from one server to another
Feb 08, 2012 : will replication from 5.5.20 to 5.0.XX server work?
Here is a Windows Batch Script to mysqldump all databases except the mysql schema and then dump the mysql schema in pure SQL:
rem
rem Startup Settings
rem
set MYSQL_CONN=-uroot -prootpassword
set MYSQLDUMP_OUTPUT=C:\LocalDump.sql
set MYSQL_USERGRANTS=C:\LocalGrants.sql
set MYSQL_TEMPGRANTS=C:\TempGrants.sql
rem
rem Get MySQL User Data
rem
set MYSQLDUMP_OPTIONS=--routines --triggers --databases
set SQLSTMT=SELECT CONCAT('mysqldump %MYSQL_CONN% %MYSQLDUMP_OPTIONS% ',DBList)
set SQLSTMT=%SQLSTMT% FROM (SELECT GROUP_CONCAT(schema_name SEPARATOR ' ') DBList
set SQLSTMT=%SQLSTMT% FROM information_schema.schemata WHERE schema_name NOT IN
set SQLSTMT=%SQLSTMT% ('information_schema','mysql','performance_schema')) A
echo echo off > C:\RunLocalDump.bat
mysql %MYSQL_CONN% -ANe"%SQLSTMT%" >> C:\RunLocalDump.bat
C:\RunLocalDump.bat > %MYSQLDUMP_OUTPUT%
rem
rem Get MySQL User Grants
rem
set SQLSTMT=SELECT CONCAT('SHOW GRANTS FOR ''',user,'''#''',host,''';')
set SQLSTMT=%SQLSTMT% FROM mysql.user WHERE LENGTH(user)
echo %SQLSTMT%
mysql %MYSQL_CONN% -ANe"%SQLSTMT%" > %MYSQL_TEMPGRANTS%
mysql %MYSQL_CONN% -AN < %MYSQL_TEMPGRANTS% > %MYSQL_USERGRANTS%
del %MYSQL_TEMPGRANTS%
Once you create the mysqldump and the Grants File, simply copy them to the Linux Server execute them locally. Execute the mysqldump first. Then, load the grants.
Give it a Try !!!
You would not need to convert the tables. The SQL dump from the Windows server would be easy to import into MySQL on Linux.
No the tables will be fine. You should also be able to transfer the config files over without issue
using mysqldump and then just the mysql command to restore the backup
You can export your database (tables with data). Then you will get sql script file. If you run that script file in your new system your tables and data will be available in the new system