I have a huge table that contains 20K records with BLOB (picture) coloumn.Its located in Localhost port 3308 in XAMPP Portable.
Now i need to move this table to another database (port 3306) in the same server.
I try to copy-paste all records (copy from 3308, paste to 3306) it directly (using Navicat) but it failed.
I try to copy-paste the records partially (5K records at a time). It still fails.
the errors are the same : mysql server has gone away. it seems that the data is too large to be copied into.
How can i possibly do this ?
The "server" is : Win 7 64 bit, 6Gb Ram, Core i3. (i know, its far from server spec.). I have 2 mysql server running, one at port 3306 running native Mysql and the other one running with XAMPP at port 3308
Thanks
You can export the data from command line with
mysqldump -u [username] -p [database-name] > file-name.sql
That will prompt you for the password.
Then you need to transfer it to the other machine, and import it with
mysql -u [username2] -p [database-name2] < file-name.sql
Related
I have a very large MySQL database (total 2027 files and 4.81gb in mysql/data) which is used for a Drupal site. I have some work to do on this and have downloaded the database to my workstation (to be strictly accurate, I loaded it into a VirtualBox VM running Windows under OS X), successfully loaded it into mysql (so I actually have the site running in the VM, using Acquia DevDesktop to run everything).
I want to backup the database, so do the classic command-line:
mysqldump -u drupaluser eco > 20160305-eco.sql
Trouble is, the operation causes the mysql server to crash on a very large table. I get the message that mysqldump "lost connection to MySQL server during query when dumping" the table at row 3134695.
And indeed, the server is crashed and has to be restarted.
I wondered whether there might be a memory problem so tried with these options:
mysqldump -u drupaluser --skip-extended-insert --quick eco > 20160305-eco.sql
But this gave me exactly the same error. Has anyone any ideas of mysqldump options that might help me round this?
Read this for general tips on making mysqldump go fast. https://dba.stackexchange.com/questions/20/how-can-i-optimize-a-mysqldump-of-a-large-database
Make sure your database is quiet before dumping it. It should not have other active clients running against it.
You already tried --quick . It keeps your large innodb tables from blowing out your transaction buffers.
Try giving your VM more disk space. You may be running out.
Dump your tables one at a time, biggest first.
Try running your mysqldump on your mac. Your virtualbox vm has an IP address, something like 192.168.137.100. Read this to learn about finding out this IP address. https://forums.virtualbox.org/viewtopic.php?f=1&t=36592
Then, on a shell in your mac do this.
mysqldump -h 192.168.xxx.xxx -u username -p password etc etc
This should connect the mysqldump on your mac to the mysql instance in your vm, and dump the table or tables you mention.
In order to load databases to mysql using terminal, as shown here, the sql file must be already in the server? Or I can upload from my local pc?
If you have mysql installed in your local machine: then you can at once run the import command from local machine's command line
mysql -hmy_server -umy_user -p database_name < full/path/to/file.sql
or you can just go to the directory where your sql file exists and run
mysql -hmy_server -umy_user -p database_name < file.sql
(password will be required after hitting Enter). This way the file will be imported into the remote database from your local computer.
No mysql is installed in your local machine: in this case you have to manually upload the file into the server with some ftp client and then connect remotely(e.g. by Putty) and run similar command
mysql -umy_user -p database_name < path/to/sql/file.sql
Yes. You can SCP or SFTP it to the server, but that command expects a file on the machine. In fact, that particular command expects it to be in the same directory that you are in.
Assuming the file contains SQL statements it can go anywhere. What is important is that the MySQL client you use to read the file can access the database server - usually on port 3306 for MySQL.
On the server, unless your local directory is accessible via network to the server (i.e. network share on another machine which is mapped to some address on your server - convoluted but essentially possible).
Basically, just upload the file to the server and run the command locally there.
NO, the SQL file or SQL script file generally can be present in your machine. When you execute the command, said sql script gets executed against the database.
mysql -u user -p -h servername DB < [Full Path]/test.sql
I have cPanel & WHM installed on my server.
Is it safe to backup this directory (if I only care about backing up the MySQL databases):
"/var/lib/mysql/"
I don't care about the other MySQL databases that cPanel provide by default. I only care about the MySQL databases that other cPanel users have created and currently own.
I know I could just back it up with other ways, but let's say due to a hard disk drive failure, I cannot access cPanel and WHM.
The only access to the server I have is via SSH (and SFTP).
Okay, so would it be my best interest to just download everything in "/var/lib/mysql/"?
If not, what other files would I need to back up? Let me guess, just the "/home/" directory?
I hope my description of my issue was made clear and was descriptive.
Basically, I need to transfer the MySQL databases from one HDD to another, but the HDD with the MySQL databases has lots of errors, is corrupted (I cannot access cPanel/WHM) and my server provider tells me my HDD has failed.
In advance, I would like to thank you very much for your help.
Even if you did not help, thank you very much for taking your time reading this. It is much appreciated.
You mentioned that you can access the server via SSH but have no access to WHM or cPanel. I guess you have no access to phpMyAdmin(?). I am also guessing that the second HDD is on another server.
Instead of backing up a directory, I would suggest you connect via SSH to your server, then make remote backups with mysqldump, download them locally with SFTP and then import the database backups to the other HDD/server.
Connect to your server with SSH
ssh root#xxx.xxx.xxx.xx1
Where xxx.xxx.xxx.xx1 is the IP address of your first server. Give your password when prompted.
Use mysqldump to make a backup of your database(s) to the server.
mysqldump -uroot -p mydatabase1 > mydatabase1.sql
mysqldump -uroot -p mydatabase2 > mydatabase2.sql
...
Type your MySQL password when prompted and then the sql files (backups of your databases) will be created. I would suggest you don't make the backups on a publicly available directory of your server.
If you are on a Unix system you can type "ll" or "ls" to see that the .sql files have been created. Make a note of the directory in your server where the backups are located.
Terminate the SSH session:
exit
Then use your favourite SFTP program to connect to your server or use terminal like this:
sftp root#mywebsite.com
Type your password when prompted.
Navigate to the directory where the backups are located and download them by using the "GET" command:
get mydatabase1.sql
Your mydatabase1.sql backup file will be downloaded to your local machine.
Don't forget to close the session:
exit
Now SFTP to your other HDD to upload the database backups:
sftp root#xxx.xxx.xxx.xx2
where xxx.xxx.xxx.xx2 is the IP address of your other machine. Give password when prompted.
Don't forget to close the SFTP session:
exit
Now that you have uploaded the databases, you can connect again with SSH to the other HDD/server just like before:
ssh root#xxx.xxx.xxx.xx2
Once connected, create the new database:
mysql -uroot -e "create database mydatabase1"
Import the backup to the database:
mysql -uroot -p mydatabase1 < mydatabase1.sql
Now the database backup should be imported in the new server/hdd. I hope this helps.
I have a local MYSQL DB running under WAMP that I need to move up to my production DB server. New to MySQL and need to know the best way to get this DB moved up.
you can run this on your current server:
mysqldump -u user -p database_name > dump.txt
and then do this on your new server:
mysql -u user -p database_name < dump.txt
Replace "user" with your username and "database_name" with a name of your database. You'll be prompted for a password in both cases
Note that second command will replace old tables in your new database
Open up your database in phpMyAdmin and then select Export from the menu. Scroll down and select the Save as file checkbox and then press Go.
Now open up the database in phpMyAdmin on the production server (Note: you will need to create the database first) and then select Import from the menu. Browser to the file you saved and press Go.
If everything goes well you should now have a mirror image of your database on the production server! :)
Do you have phpmyadmin? (If you're not sure, type "http://localhost/phpmyadmin"). If you do, go to "Export on your local computer, and then upload that file on the "Import" section of the remote server. This is the absolute easiest way, and 90% of hosts have phpmyadmin installed.
If you don't, use the command line method suggested by ZeppLock.
I have a new database, similar to the old one but with more columns and tables. So the data on the old table is still useable and needs transferring.
The old database is on a different server to the new one. I want to transfer the data from one database to the other.
I have navicat, but it seems to take forever using the host to host data transfer. Also downloading a sql file then executing that takes too long also (it executes about 4 inserts per second).
The downloaded SQL file is about 40mb (with complete insert statements). The final one would probably be 60mb to 80mb.
What's the best way to transfer this data? (a process I will need to repeat a few times for testing)
Doing a mysqldump on the source machine and then slurping it in on the other side, even on a 40-100MB file is well within reason. Do it from the command line.
(source machine)
mysqldump -u user -p password database > database.sql
..transfer file to recipient machine...
(recipient machine)
mysql -u user -p password database < database.sql
Can you not transfer only a portion of the data for testing first? Then, later, transfer the entire thing when you're satisfied with test-results?
(it executes about 4 inserts per second)
That sounds more like there's something wrong with your database.. Are you sure that's alright?
Cody thank you for the direction. For some reason it did not work for me, but the below did on my redhat linux server:
(recipient machine)
mysql -u [username] -p -h localhost database < database.sql
(source machine)
I just used php myadmin
Is there a command that can be run to pull the DB from another server something along the lines of: mysqldump -u [username] -p -h [host address] [dbname] > [filename].sql
Thanks