Back-up of all tables in a database as sql file - mysql

I am trying to create a back-up of all tables in a large mysql database having all tables as .sql file, this is what I am trying:
`mysqldump -h localhost --user=username --password --tab=/tmp/test
db_name`
this is the error i get:
`Got error: 1045: "Access denied for user 'username#%' (using password: YES)" when executing 'SELECT INTO OUTFILE'`
I have spent lot of time searching for a solution for this error but I could not find anyone that could solve the issue.
Of course the directory test permissions are ok, I have already checked that.
Thank you.

Don't enter the password with command. Just enter,
mysqldump -h localhost -u username -p db_name > backup_file.sql
Then you will get a prompt to enter password. Enter that and it should do the trick.
Thanks

Related

cannot connect to database from zapier #1044 - Access denied for user

I am trying to connect Zapier to my Database. Zapier has very limited support for this and seem to be going round in circles.
I need to GRANT SELECT to a user on my database with this code;
GRANT SELECT ON my-database-here.my-table-here TO 'user-here'#'ip-address-here' IDENTIFIED BY 'my-password-here';
The error i receive is;
#1044 - Access denied for user 'xxx'#'localhost' to database 'xxxx'
The user has ALL PRIVILEGES but can't seem to get it to work. Any help here could be greatly received.
Thanks
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
you have 2 issues:
1 => mysql -uroot -p should be typed in bash (also known as your terminal) not in MySQL
command-line. You fix this error by typing.
exit
in your MySQL command-line. Now you are back in your bash/terminal command-line.
You have a syntax error:
mysql -uroot -p;
the semicolon in front of -p needs to go. The correct syntax is:
mysql -uroot -p
type the correct syntax in your bash commandline. Enter a password if you have one set up; else just hit the enter button. You should get a response that is similar to this:

Can't login into mysql

I've just downloaded MySql using this tutorial after installing it before.
I've thought that it would solve my problems but, whenever I try to login into MySql via the terminal I'm prompted to enter the password though I've already logged in with the following command:
mysql -u user -p password
Here is what happening:
$> mysql -u user -p MYPASSWORD
Enter password:
And after I insert my password again...
$> mysql -u user -p MYPASSWORD
Enter password:
ERROR 1049 (42000): Unknown database 'MYPASSWORD'
I'd like to know if there's a solution to this weird problem.
The command is:
mysql -u user -ppassword
So in your case:
mysql -u user -p123456
By adding a space between -p and your password, you're actually setting the database to use, which is why you get the error unknown database.
The other solution would be:
mysql -u user -p
In that case, your password will be asked by the terminal. It is a bit more secure as your password does not stay in plain text in your terminal history. But if your password is 123456, I guess you're not too concerned by security ... ;)
Under normal circumstances, I would use:
mysql -uroot -p
Enter password:
you can try it.... ;)

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.

How can I fix the MySQL 'access denied' errors after db restore?

I exported all databases of a MySQL server by:
mysqldump -u root -p --all-databases > /tmp/dbs.sql
Then I copied the file (by scp) on another server, which has the same MySQL version, and imported it with:
mysql -u root -p < dbs.sql
I can access to MySQL only as root. With other users, I obtain:
~$ mysql -u jag -p
Enter password:
ERROR 1045 (28000): Access denied for user 'jag'#'localhost' (using password: YES)
However, selecting all users in mysql.user table, I can see that all user accounts where imported. So, how can I overcome this problem, without resetting all user passwords?
You need to specify username and password, you can try this:
mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME
Note that there is no space between -p parameter and password!
You can check this: http://dev.mysql.com/doc/refman/5.0/en/connecting.html
After following all the similar answers for this issue, I've solved it in CentOS with this:
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
please make sure to grant privileges to that user u want to restore with, in this case 'jag'

Updating a database in a server using command-line

I have been searching for a while to find a good answer to my problem.
I have a new server where I would like to run a script in .php which uses a database to store some data. What I have done so far is:
Place the .php file in the server with the help of Putty.
Create a database in phpmyadmin, export it and place it in the same folder of my project in putty.
Run php5 crawl.php > logfile.log 2&>1&
but it doesn't update the database.
I am little bit confused with the steps I have to make in order to make it work. I have been reading also this article http://www.aspkin.com/using-putty-to-import-a-database/ but when I run the
mysql -u dbusername -p databasename < backupname.sql
I get this error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Any idea what I might be doing wrong?
if it's a local machine you may not have a password on it for root - so remove the -p tag.
Otherwise you want to specify the password in there with it, without a space, like so:
mysql -u dbusername -pYourPassword databasename < backupname.sql
zcat /path/to/file.sql.gz | mysql -uroot -p your_database