I'm ssh-ed into a remote MySQL server through my Mac OS terminal. I'm in a database and looking at a table I want to download to my desktop. How do I download it? I've heard of mysqldump, but it confuses me. I'm very new to mySQL and databases in general and can't risk messing up this database somehow. Can someone give me the exact command to download a table? Thank you in advance!
if you're logged in using ssh that means you have access to a shell. find the location of the database file and then use scp to download it.
the command would look something like this:
scp -P 1234 user1#mysql.server.com:/location/of/source/file /location/of/destination
-P 1234: port number 1234 (may vary in your case)
user1: username
mysql.server.com: domain
/location/of/source/file: location of the database file on the server
/location/of/destination: location where you want to save the file on your computer
you also want to make sure you have necessary rights to copy the file using scp.
after you download it you can use a database browser to check out the contents.
Related
Guys I am trying to import database from a folder in the laptop to a live server via putty.
I have tried using:
mysql -u root -p dbname <"c:\path to database.file.sql"
I have also tried to use:
c:\path to database mysql -u root -p <file.sql
,but all in vain saying directory not found.
How can I import database from folder in laptop direct to centos via putty command line ?
First of all you should transfer the file from your computer to your CentOS Server.
I will suggest using WinSCP, (I prefer for not large size file transfers) it is very easy to use and it can help you a lot for the files edit, too.
You should make a new connection putting your Server IP, username and password.
After that you can use drag and drop for files transfer.
You can use https://cyberduck.io/ , if you want.
For copying tables or databases from local environment to my remote server, I use SQLYog - https://code.google.com/archive/p/sqlyog/wikis/Downloads.wiki
I setup the connections to my remote environment and then to my server. Then, all you need to do is copy the database from one host to the other
Then select the remote host, database to which data should be copied and let the software do the rest of the work.
I am using phpmyadmin on my windows os. I have a database with one table which has 100M records with the size of 20GB. I want to export this table and have the table.sql file. Whenever I try to do this, the size of the exported file is 0 bytes. When I check the apache error log, the following would show up:
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1066139648 bytes)
Any idea how to solve this problem?!
Thanks :)
I would suggest to try using the command line and the mysqldump.exe utility, as suggested here
If you have shared hosting and you are using Cpanel then they are providing you the option to backup your database in the following section.
Files => Backup => Download a MySQL Database Backup.
If you are on a shared hosting or you don't have access to shell, then use mysqldumper script; copy it to your server and start it in your browser under "yourDomain.com/path_to_mysqlumper/"
MySQLDumper is a PHP and Perl based tool for backing up MySQL
databases. You can easily dump your data into a backup file and - if
needed - restore it. It is especially suited for shared hosting
webspaces, where you don't have shell access.
If you have shell access to your host servers (if provided by your host since not all shared server hosters give this access) then you may use SSH access like in this tutorial using Putty that you install and configure then import or export your databases like in this third tutorial.
I try mysqldump for many hours but didnt work, until I started a superuser console.
First, start a superuser console
sudo su
Then, try the complete command
/opt/lampp/bin/mysqldump -u root -p [DATABASE NAME] > [PATH_FOR_BACKUPFILE]/[FILE_NAME].sql
I my case, it was something like /opt/lampp/bin/mysqldump -u root -p database > /home/user/backup.sql
MySQLDumper worked like a charm for me at my hosted website. I had to copy one database and "paste" it into a new database. In MySQLDumper, it isn't apparent right away how to do this, but the key is to create a new configuration file in MySQLDumper and that will allow you to copy/restore to different databases.
On the home screen in MySQLDumper, click Configuration, then Configuration Files. There is a text box at the top allowing you to create a new Configuration file. In there, put in the information for the second database you need (you created a connection to the first database when you install MySQLDumper). Save it. Then you can click Restore where you can select the dump of the first database and restore it in the second one.
This was a lifesaver. Thanks!
increase
max_post_size
variable in php.ini file. Then you will be able to download it.
I had a different issue when I was downloading from phpmyadmin in the middle like 180MB download stops with message - network error
So I used ssh connection which you can find in your cpanel sometimes they provide browser based terminal or sometime you have to access it using putty .
In terminal I go inside my public_html folder where all my files are stored . Followed by this command:
mysqldump -u [username] -p [database-you-want-to-dump] > [path-to-place-data-dump.sql]
This did the job in few minutes and saved a sql file in my public_html folder. Then I opened the folder in File manager and downloaded it from there.
You can also use FTP or you can download it directory by accessing by url.
Make sure you delete it after your download finishes.
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.
I have a file called database.dmp that is the mysql dump from the server last night. User is probably root.
I want to create a local copy on my computer 'MARK-PC' (I definitely do not overwrite the live database on the server).
What is the best command to do this?
1a. Can I use that command from the microsoft windows command prompt? I am not that familiar with the mysqldump command line and don't want to screw anything up.
Will I need to have root access?
If I set it up with another user/password, what issues will I run into if any?
I am using phpmyadmin on my windows os. I have a database with one table which has 100M records with the size of 20GB. I want to export this table and have the table.sql file. Whenever I try to do this, the size of the exported file is 0 bytes. When I check the apache error log, the following would show up:
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1066139648 bytes)
Any idea how to solve this problem?!
Thanks :)
I would suggest to try using the command line and the mysqldump.exe utility, as suggested here
If you have shared hosting and you are using Cpanel then they are providing you the option to backup your database in the following section.
Files => Backup => Download a MySQL Database Backup.
If you are on a shared hosting or you don't have access to shell, then use mysqldumper script; copy it to your server and start it in your browser under "yourDomain.com/path_to_mysqlumper/"
MySQLDumper is a PHP and Perl based tool for backing up MySQL
databases. You can easily dump your data into a backup file and - if
needed - restore it. It is especially suited for shared hosting
webspaces, where you don't have shell access.
If you have shell access to your host servers (if provided by your host since not all shared server hosters give this access) then you may use SSH access like in this tutorial using Putty that you install and configure then import or export your databases like in this third tutorial.
I try mysqldump for many hours but didnt work, until I started a superuser console.
First, start a superuser console
sudo su
Then, try the complete command
/opt/lampp/bin/mysqldump -u root -p [DATABASE NAME] > [PATH_FOR_BACKUPFILE]/[FILE_NAME].sql
I my case, it was something like /opt/lampp/bin/mysqldump -u root -p database > /home/user/backup.sql
MySQLDumper worked like a charm for me at my hosted website. I had to copy one database and "paste" it into a new database. In MySQLDumper, it isn't apparent right away how to do this, but the key is to create a new configuration file in MySQLDumper and that will allow you to copy/restore to different databases.
On the home screen in MySQLDumper, click Configuration, then Configuration Files. There is a text box at the top allowing you to create a new Configuration file. In there, put in the information for the second database you need (you created a connection to the first database when you install MySQLDumper). Save it. Then you can click Restore where you can select the dump of the first database and restore it in the second one.
This was a lifesaver. Thanks!
increase
max_post_size
variable in php.ini file. Then you will be able to download it.
I had a different issue when I was downloading from phpmyadmin in the middle like 180MB download stops with message - network error
So I used ssh connection which you can find in your cpanel sometimes they provide browser based terminal or sometime you have to access it using putty .
In terminal I go inside my public_html folder where all my files are stored . Followed by this command:
mysqldump -u [username] -p [database-you-want-to-dump] > [path-to-place-data-dump.sql]
This did the job in few minutes and saved a sql file in my public_html folder. Then I opened the folder in File manager and downloaded it from there.
You can also use FTP or you can download it directory by accessing by url.
Make sure you delete it after your download finishes.