AWS EC2 Crontab auto backup RDS MySQL database - mysql

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

Related

cloning MySQL database using mysqldump

I am trying to copy my database with a different name. I've found this:
$ mysqldump yourFirstDatabase -u user -ppassword > yourDatabase.sql
$ mysql yourSecondDatabase -u user -ppassword < yourDatabase.sql
But I do not understand clearly.
So I have 2 databases: lab1, lab2. lab2 contains 0 tables since I want this to be a copy of lab1.
So 'lab1' is 'yourFirstDatabase' and lab2 is 'yourSecondDatabase', right? then what is 'yourDatabase?'
Also I got the error below:
$ mysqldump -uroot lab1 -u user -ppassword > yourDatabase.sql;
mysqldump: [Warning] Using a password on the command line interface
can be insecure. mysqldump: Got error: 1045: Access denied for user
'user'#'localhost' (using password: YES) when trying to connect
process work just like you said.For yourDatabese you are creating a temporary backup file that is used only for transferring yourFirstDatabase

Installing snort, having trouble with SQL root password

So I am installing snort currently on my ubuntu linux server. I am following this guide here.
At this point, I am at the part in the guide where I am installing Barnyard2 and i need to access my SQL database to save information. linux server is near fresh install with little else on it. When I try to do this part of the guide:
echo "create database snort;" | mysql -u root -p
mysql -u root -p -D snort < ~/snort_src/barnyard2-master/schemas/create_mysql
echo "grant create, insert, select, delete, update on snort.* to \
snort#localhost identified by 'MYSQLSNORTPASSWORD'" | mysql -u root -p
When I run the first line - if I don't enter anything, I get the error message that says:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
If I do enter something, I get a different error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I have tried using this in order to reset my password but the command mysql -u root or any form of command similiar results back in the same error, even when it says the password is probably not required for this command. Does anyone know a way in which I can get this to work?
Why don't you break that down into chunks?
First make the database:
$ mysql -u root -p -e 'CREATE DATABASE `snort`'
Import the barnyard schema
$ mysql -u root -p < ~/snort_src/barnyard2-master/schemas/create_mysql
Now create the user & assign permissions for the snort db to the barnyard user
$ mysql -u root -p -e 'GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON `snort`.* TO snort#localhost IDENTIFIED BY '[SNORT PASSSWORD]'
The commands in your question are running a local mysql client which assumes to connect to a local database by default. If your database is running on a neighbouring Windows box you will need to rethink your parameters.
mysql -u root -p -h 192.168.0.99

mysqldump: Got error: 1045 Access denied

I am logged into an AWS instance and trying to copy a mysql database to a .sql file. I am using the command:
mysqldump -u [username] -p [databasename] > [database].sql
Then entering the password and the following message comes up.
"mysqldump: Got error: 1045: Access denied for user '[username]'#'localhost' (using password: YES) when trying to connect."
I can login directly to mysql using the same credentials as above, but still get the same error.
I have tried a bunch of different ways for the command above, but it seems to be an issue with permissions or something similar. The user does have all privileges for the database when looking in phpmyadmin so I am not sure what is wrong? Any suggestions? Thanks
This works for me:
mysqldump -uroot -pxxxx dbname > dump.sql
or you can specify the host:
mysqldump -h localhost.localdomain -uroot -pxxxx dbname > dump.sql
Check to make sure you don't have different instances of mysql running
Thank you all for your input! It got me thinking about what else it could possibly be. I then tried using the -h parameter as well, which wouldn't work with "localhost". It finally worked when I used the Private IP Address for the AWS instance.
mysqldump -h [PrivateIPAdress] -u [UserName] -p [DatabaseName] > [Database].sql
mysqldump -u [username] -p
ENTER YOUR PASSWORD
USE [databasename]
SOURCE /path/to/[database].sql
I am not sure, but worth a try because you said you are able to login into that machine.

access denied mysql monitor

I installed xampp on 10.9 mavericks. Unfortunately the command mysql does not work in the terminal. I managed to start the mysql monitor from xamppfiles/bin/. When I try to create a new database I get
ERROR 1044 (42000): Access denied for user ''#'localhost' to database XY
What can I do?
No, you should run mysql -u root -p in bash, not at the MySQL command-line. If you are in mysql, you can exit by typing exit.
You may need to set up a root account for your MySQL database:
In the terminal type:
mysqladmin -u root password 'root password goes here'
And then to invoke the MySQL client:
mysql -h localhost -u root -p

php can connect to remote sql server but command line can't

I'm using exactly the same credentials to connect to a remote mysql server.
host % is given to the user.
I can connect via my php application on localhost to remote mysql server
however whenever i do command line on localhost
mysql -u username -p'password' -h remoteserver.domain.com
it throws an error
ERROR 1045 (28000): Access denied for user 'username'#'10.50.2.4' (using
password: YES)
what am i missing here?
Your mysql command line is wrong. Mysql has the funky syntax of:
mysql -u username -ppassword -h remoteserver.domain.com
instead of
mysql -u username -p password -h remoteserver.domain.com
Note the p tag and password placement.
turns out that i should do away single quotes in my password for windows-based mysql command
instead of
mysql -u username -p'password' -h remoteserver.domain.com
this actually works
mysql -u username -ppassword -h remoteserver.domain.com
reason why i use single quotes because my password contains non-alpha characters which works in linux but not on windows based command line