Could not connect: Access denied for user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Joel Phelan
    New Member
    • Mar 2011
    • 4

    Could not connect: Access denied for user

    I am getting the below error when attempting to run a php script on my server which accesses a mysql table I have created in an existing database. I can connect to the database table via the MySQL workbench, but not via a php script I have written. This database was originally created for use with Magento Cart, which I have installed and which works correctly (can access it's database tables). I simply cannot access the database with a separate script which I have separately created. The script runs and echoes the statement to the screen, but then fails on the connection.

    Could not connect: Access denied for user 'cars2'@'VWEB2' (using password: YES)PHP Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'cars2'@'VWEB2' (using password: YES) in C:\HostingSpace s\car.accessori es\caraccessori es.com\wwwroot\ magento\uploadQ uestion.php on line 4


    ------------------php script--------------

    Code:
    <?php
    
    echo "test<br>";
    $con = mysql_connect("server", "username", "password");
    
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("cars2", $con);
    
    $sql="INSERT INTO survey_questions (survey_question_text, survey_question_visible, survey_question_options, survey_question_style) VALUES ('$_POST[survey_question_text]',,'$_POST[survey_question_status]','$_POST[survey_question_options]', '$_POST[survey_question_style]] )";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con);
    
    ?>
    Last edited by Niheel; May 29 '11, 07:22 AM.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    User cars2 does not have privileges to connect to the database from server VWEB2.

    Comment

    • Joel Phelan
      New Member
      • Mar 2011
      • 4

      #3
      The user cars2 is the user account that my Magento installation uses to connect to the very same database from the very same server. Ergo, it has the appropriate permissions at the database level. This is a new table in the existing database.

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        Run this query in MySQL and post the results here
        [CODE=mysql]SHOW GRANTS FOR 'cars2'@'VWEB2' ;[/CODE]

        Did you specify the same server name for Magento in mysql_connect() ?

        Comment

        • Joel Phelan
          New Member
          • Mar 2011
          • 4

          #5
          The server name was specified as the server name (which is sql2.domainname .com). The return of the statements is below (first is with the vweb2 host, second is without. I'm not sure where the vweb2 is coming from, unless it is an internal network DNS name that is being applied by the server.

          SHOW GRANTS FOR 'cars2'@'VWEB2'
          Error Code: 1141
          There is no such grant defined for user 'cars2' on host 'VWEB2'

          If I use the actual server name, I get the same thing
          SHOW GRANTS FOR 'cars2'@'sql2.h ost.com'
          Error Code: 1141
          There is no such grant defined for user 'cars2' on host 'sql2.host.com'

          SHOW GRANTS FOR 'cars2';
          (which appends @%)
          2 row(s) returned
          'GRANT USAGE ON *.* TO ''cars2''@''%'' IDENTIFIED BY PASSWORD ''*B2BE71AE30F6 0BB25F7C6B25C77 591F34E20BE99'' '

          'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE ON `cars2`.* TO ''cars2''@''%'' WITH GRANT OPTION'

          Comment

          • Joel Phelan
            New Member
            • Mar 2011
            • 4

            #6
            Late update on this resolution... I'd stored the password in MySQL Workbench, and so hadn't been typing it in for a while. My host changed the password a while back. I updated it in Workbench, but never got rid of the original e-mail... short version, I was using the wrong password to try to connect.

            Comment

            Working...