Not able to connect to MySQL database.

Posted on 2012-09-17
Last Modified: 2012-10-11
I am installing OPSI 4 on CentOS 5 server. For that i have to configure mysql. When i trying to connect to mysql i getting following error.

"Failed to connect to host 'localhost' as user 'root' : (1045, "Access denied for user 'root'@'localhost' (using password : NO)")

Please help.
Question by:vipinvgopal
    LVL 39

    Expert Comment

    by:Roger Baklund
    You are trying to connect without a password, but a password is required.
    LVL 9

    Expert Comment

    Can you post the mysql query here.

    Author Comment

    I changed root password for mysql. Now its showing following error
    Re: Err :1045 Access denied for user 'root@localhost'(using password: YES)

    Please help.
    LVL 39

    Expert Comment

    by:Roger Baklund
    The message says it all, this time you are using a password, but not the right one.

    Beware that mysql user accounts are identified by user/host combination, i.e. the user 'root@localhost' might have a different password from for instance 'root@' or 'root@%'.
    LVL 15

    Assisted Solution

    check the users table in mysql database.
    Check whether you have provided proper users to it or not.
    Check what host and user you have assigned. Probably host part has been assigned wrong.
    How you are trying to access mysql by which scripting language. check what host you have provided .
    LVL 2

    Accepted Solution


    seems like your username and password does not match with each other..

    follow these steps to recover you ROOT password.

       1.  Stop MySql server by /etc/init.d/mysqld stop
       2.  Start MySql In safe mode with : mysqld_safe --skip-grant-tables &
       3.  Connect to mysql client using mysql -u root
       4.  select mysql database with : use mysql
       5.  Change the Password of Root with : update user
            set password=password('newpassword') where user='root'
       7.  quit
       8.  Stop mysqld with /etc/init.d/mysqld stop
       9.  Start mysqld with /etc/init.d/mysqld start
      10. restart mysql with new password  

      now you can connect with your MySQL server with root user..

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now