I have Mysql installed on my local PC and want to use mysqldump on my local pc to dump a remote database. So I open CMD and run the following command:
mysqldump -P 3306 -h 12.43.33.43 -u admin -p myDatabase > mydb.sql
So in the next line it should ask for my password? but instead i get the response 'Access is denied'. Am i missing something here?
ps.
If I try the following:
mysqldump -P 3306 -h 12.43.33.43 -u admin -p myDatabase
it will successfully ask for my password and start printing the dump in cmd, but this is no good as i need the response saved in a file.
I only wanted to know if you could connect.
The command is
mysqldump -P 3306 -h 12.43.33.43 -u admin -p --databases myDatabase --result-file=mydb.sql
As the connection is not secure, you send your credentials like a postcard, so that every one can read it.
Besides that having your server exposed to the internet, is very dangerous and can come to a disaster, so reconsider your security strategy and allow only access via ssh.
Related
How can I do a mysqldump from a server by using the Terminal?
I did the following:
First of all I logged in:
ssh root#123.456.78.90 // then I enter my password
then I do:
mysql->show databases;
after that:
use the_database;
then I do:
mysqldump -u myusername -p the_database > db_backup.sql
after that, obviously, nothing happens and I do not get an error. So my question is, where does it save the backup and how can I get a the mysqldump on my local machine?
There are multiple ways of how and where to backup, but most probably you would not like to store your backup in the same server where you are running the database.
If you have ssh access to the server you could create an ssh-tunnel, the most basic example of this could be:
$ ssh -L 3307:localhost:3306 root#123.456.78.90
What this will do is to open port 3307 locally (just in case you already are using 3306) and forward it to localhost:3306 going through 123.456.78.90
Then you could do something like:
$ mysqldump -h localhost -P 3307 -u myusername -p the_database > db_backup.sql
To know your current path, run pwd it will print your current directory and in where the db_backup.sql will be created in case you don't specify and absolute path.
Without using ssh you could also try to connect directly by just specifying the host:
$ mysqldump -h 123.456.78.90 -u myusername -p the_database > db_backup.sql
In case the port is open probably you will need just to modify/grant the user permissions to allow your IP to access:
mysql> GRANT ALL ON the_database.* TO your_user#'123.456.78.90' IDENTIFIED BY 'secret';
Connect to your server using ssh command.
run below code
mysqldump -u userName -p databaseName > /path/to/backup.sql
the location path must be on same server
I have an SSH access to production server of the Rails app.
I want to make a mysqldump of production database to my Mac. Please help me to achieve this.
Direct method to dump mysql data from remote server to your local computer is:
ssh root#ipaddress "mysqldump -u dbuser -p dbname | gzip -9" > dblocal.sql.gz
Or
ssh -l root ipaddress "mysqldump -u dbuser -p dbname | gzip -9" > dblocal.sql.gz
Both command does the same work.
If you have password for ssh and database access there will two prompt for password or if you have no password for ssh then you will be asked to enter you database password.
Similarly, if you are using key from aws or cloud other service you can incorporate the key in the command as:
ssh -i key.pem root#ipaddress "mysqldump -u dbuser -p dbname | gzip -9" > dblocal.sql.gz
Connect to server via ssh: ssh remote_username#remote_host
Go to 'current' folder
Make a dump: mysqldump -u username -ppassword -h host database > dump.sql
Disconnect from server
Copy a dump.sql file to local computer: scp remote_username#remote_host:/path/to/dump.sql /Users/YourName/Documents/dump.sql
Connect to server via ssh again and go to 'current' folder
Remove dump.sql file: rm dump.sql
I couldn't get the other ones to work.
This is the solution I found for linux:
ssh username#ipadress "mysqldump -u USERNAME -pPASSWORD DB_NAME " > ~/dump.sql
This will prompt you to enter a password for your ssh server, and then dumps the database to the specified location on the SSH server.
I am trying to get database backup from remote system, please anyone help me to get backup from remote system. Here is the query which I executed, but its giving error.
mysqldump --host <host or IP address> -P <port Number> -u <username> -p<password> databaseName > c.sql;
remove ; from your syntax and execute below command-
mysqldump -h<IP_address> -u <username> -p<password> databaseName > backup.sql
If you want to take backup in your working directory else give a path. I have removed port option here as assuming that it will be running on default port 3306 else add in command.
Make sure your user should have permission on db server.
I have a MySQL database existing on a remote server. I only have sql connection privilege. I don't have FTP access to the server, and I need to do a complete dump of the database. I have tried mysqldump, but the issue is that it is creating the output on the server and as I don't have FTP I can not get the output from the server.
How can I do a clean backup and get the dump in my local machine(of course, the backup should be restored in my local machine)?
You can specify the server name as an option to mysqldump:
mysqldump --host servername dbname > dbname.sql
mysqldump --host hostaddress -P portnumber -u username -ppassword dbname > dbname.sql
Normally the remote port of MySQL is 3306. Here is an example:
mysqldump --host 192.168.1.15 -P 3306 -u dev -pmjQ9Y mydb > mydb.sql
You can use the MySQL workbench http://www.mysql.com/products/workbench/, which can backup directly to a local folder through a user-friendly interface
mysqldump.exe locks tables by default, so other SQL actions are not possible during a dump. Without locking any tables, use the following syntax to backup a complete remote db and dump everything on your local machine:
mysqldump -u username -p --single-transaction --quick --lock-tables=false -h ipaddress myDB > backup.sql
Change username into your own username, change ipaddress into the remote ip address, and myDB to the actual database you want to backup. This will prompt you for your password. Once provided, the dump starts.
I use SQLyog for this where we can connect to the remote server and take a back up with this tool.
If the server admits PHP, you can upload and try Adminer. I like it as a PHPMyAdmin replacer, and you can create backups with it!
Can anybody tell me that how to get DB backup script from Remote Server in MySQL using command-line utility?
I'm using a command as follows, but not working:
C:\>mysqldump -h <server ip> -u <user-id> -p <password> <db name> >
E:\dumpfilename.sql
The syntax for the password is wrong. You need to write the password immediately after the -p, without a space. That's why the password is interpreted as the database name.
Write this instead:
C:\>mysqldump -h <server ip> -u <user-id> -p<password> <db name> >
E:\dumpfilename.sql
Notice how there is no space after -p. An example would be -phunter2, where the password is "hunter2".