Search code examples
mysqlaccess-denied

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?


Solution

  • 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