mysqldump: Got error: 1045: Access denied for user 'root'@'localhost'

7 posts / 0 new
Last post
#1 Wed, 02/01/2012 - 10:16
bwade30

mysqldump: Got error: 1045: Access denied for user 'root'@'localhost'

Hi when I run this command from ssh via root it doesn't work. How do I get it to work without using the password? On my other servers it's possible to run this command and it just works.

[root@- www]# mysqldump db > file.sql mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: NO) when trying to connect

BTW, i'm running centos 6.2 64bit in root via command prompt ssh in latest vmin/wmin

Wed, 02/01/2012 - 11:19
andreychek

Howdy,

You'd just need to add in a -p parameter, so that it'll prompt you for a password. You can do that like this:

mysqldump -p db > file.sql

Wed, 02/01/2012 - 11:30
bwade30

ok, but on other servers no password is required since I'm already logged in as root it trumps all passwords normally. This is for an sh script so how would I get it so no password is prompted and it just dumps it without interuption.

also, what's the >

Wed, 02/01/2012 - 12:06
andreychek

MySQL would always require you to enter a password, if there is one set for the user you're accessing.

The root user would indeed not require you to enter a password when accessing other user accounts on the server, but that's different from accessing MySQL-based accounts.

Regarding the ">" in your command -- that redirects the output of the mysqldump command into a file, rather than having it all display on the screen.

-Eric

Tue, 02/14/2012 - 15:05
mfleeson

Hi, You can store your root password in a local user version of .my.cnf which is read by the mysql commandline tools. More info:

Once mysql-server is installed it is ready for immediate use. However, it is best to at least set an admin password with:

$ /usr/bin/mysqladmin -u root password 'new-password'

You will then also need to let cron jobs work on the database so create a personal mysql config file for root in /root/.my.cnf containing:

[mysqladmin] user = root password =

Make sure the permissions are set appropriately:

# chmod 0600 /root/.my.cnf # ls -l /root/.my.cnf 4.0k -rw------- 1 root root 64 Oct 12 10:52 /root/.my.cnf

Best Wishes

Mark Fleeson

Thu, 07/19/2012 - 10:42
chitoz

i have this problem too!
in my old server (with cPanel/WHM) i use a shell backup script that execute this command:
mysqldump -u root DB_NAME > BACKUP_PATH.sql

in my new server (that use virtualmin), the command accrues an error:
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: NO) when trying to connect

it not seems safe to put root password (or password of any user that have full access to database) in simple backup.sh file! isn't it?!

(i also use the `mfleeson` note but the problem not solved.)

Sat, 07/21/2012 - 06:27 (Reply to #6)
chitoz

thanks to mfleeson note. i use # sign in password and this cause problem in .my.cnf file.

Topic locked