cloning MySQL database using mysqldump - mysql

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

Related

mysqldump fails on user permissions

We're using a gcp clouddsql-mysql-8 database to back up application data.
When I try to back up the database using the following parameters:
/bin/mysqldump --defaults-extra-file='/mysqldb/.database.cnf' -h <host-ip> --single-transaction --databases metadata > /mysqldb-backups/dev/deployment/depl-$(date +\%d\%m\%Y).sql
However, when running the command we get the following error:
mysqldump: Got error: 1045: Access denied for user 'admin'#'10.x.x.x' (using password: YES) when trying to connect````
Yet, we're able to log into the database successfully when using the credentials listed in the .database.cnf file
```
# mysql -h 10.x.x.x -u amin -p
```

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

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.

Unable to use database in mysql (unknown database)

I am trying to get started with the following github package: py-gameday.
I installed mysql with brew mysql and created a root password:
> mysqladmin -u root password 'xxx'
I then created a user:
> mysql -uroot -p
Enter password: xxx
CREATE USER 'josh'#'localhost' IDENTIFIED BY 'yyy';
and just in case, I reset the password again:
SET PASSWORD FOR 'josh'#'localhost' = PASSWORD('yyy');
and grant permissions:
GRANT ALL ON gameday.* TO 'josh'#'localhost';
and I then updated mydb.ini with:
[db]
user=josh
password=yyy
db=gameday
I finally tried running the following:
$ mysql -D gameday < gameday.sql -p
Enter password: yyy
ERROR 1049 (42000): Unknown database 'gameday'
Why doesn't it work? I have a gameday.sql sitting there on the directory.
You need to physically create the database in mysql. Currently the gameday.sql is just a set of commands to run in the mysql database which probably creates a bunch of tables.
You'll need to use CREATE DATABASE gameday; in mysql, then give josh permissions to write to that database. Then the mysql -D -p gameday < gameday.sql -p command should work.