Problems with Mysqldump command - mysql

I have a Debian VPS with mysql installed and i want to export a database.
After have successful login in to mysql.
I run the follow command:
mysqldump -u user -p mydatabase > db.sql
but I got the following error:
->
It doesn't export the database and I canĀ“t type anything.

you don't need to login to mysql. Just type:
mysqldump -u user -p mydatabase > db.sql
on the command line, meaning the shell. It will ask you for a password and then writes the dump to db.sql

Related

mysqldump via cmd syntax for dumping remote database

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.

AWS EC2 Crontab auto backup RDS MySQL database

In my EC2 Linux, I would like to create a cron job to auto backup a MySql DB in AWS RDS. I had tried to run
/usr/bin/mysqldump -u dbusername -p'dbpassword' dbname > /path/backup.sql
but I got an error
"Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1045: Access denied for user 'dbusername'#'localhost' (using password: YES) when trying to connect".
What is wrong and how do I change the 'dbusername'#'localhost' to 'dbusername'#'xxx.xxxxxxxx.xx-xxxxxx-x.rds.amazonaws.com'?
I had also tried to write a MySql script to download backup.sh but unable to as it cannot go beyond
mysql -u 'dbusername' --password="dbpassword" -h 'xxx.xxxxxxxx.xx-xxxxxx-x.rds.amazonaws.com'
it is able to login but it shows the MySQL prompt
>
anything beyond that e.g.
> use db;
it will show
Warning: Using a password on the command line interface can be insecure.
mysqldump -u dbusername -p'dbpassword' -h hostname.here.com dbname > /path/backup.sql
The same -h works for all mysql* commands, e.g. if you want to connect to RDB:
mysqldump -u user -p'pass' -h db.us-east-1.rds.amazonaws.com dbname

Mysql Database Backup from Remote System

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.

how to create a .sql file from terminal in ubuntu

I have created a project which is using a database , prepared in mysql. To submit this project i need to create a .sql file.
I am not using workbench. Can any one guide me on how to make the .sql file using terminal. I have created all of my database using terminal. I am working on ubuntu.
nysqldump -u db_username -p database_name > database_name.sql
Then enter and it will ask the password, enter the password and and hit enter, thats it it will create the .sql file for you
Here is an example in my ubuntu machine
abhik#ubuntu-desktop:~$ mysqldump -u root -p test >test.sql
Enter password:
abhik#ubuntu-desktop:~$
I am currently on Desktop folder so the file is saved under Desktop
If you want To export:
mysqldump -u mysql_user -p DATABASE_NAME > backup.sql
To import:
mysql -u mysql_user -p DATABASE < backup.sql

Terminal mysql queries

I'm looking to use terminal to execute mysql queries. I currently connect to a sql db via the sql workbench but would like to do this via terminal. Is this possible?
I've installed mysql via homebrew
when I hit mysql in terminal it says command not found, maybe I need to do something else besides the homebrew setup?
Go to the directory:
mysql/bin
To execute the query from command line:
mysql -u [username] -p [dbname] -e [query]
example:
mysql -u root -p database -e "select * from user"
mysql --help
You can do also:
cat dump.sql | mysql -u user -p password database
Or:
echo "select * from abc;" | mysql -u user -p password database