Access denied for user: username@%

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • red

    Access denied for user: username@%

    I know this is probably a faq but it is hard to search for this exact
    problem.
    When I put this on a php page:
    <?
    $link = mysql_connect(" localhost", "cardini", "password")
    or die("Could not connect : " . mysql_error());
    echo "Connected successfully\n" ;
    mysql_select_db ("articles") or die("Could not select database");


    $sql = 'CREATE TABLE image( id mediumint( 8 ) unsigned NOT NULL
    AUTO_INCREMENT ,'
    . ' masterid mediumint( 8 ) unsigned NOT NULL default \'0\','
    . ' filedata blob NOT NULL ,'
    . ' PRIMARY KEY ( id ) ,'
    . ' KEY master_idx( masterid ) ) TYPE = MYISAM ';
    mysql_query($sq l);
    db(mysql_error( ));
    ?>
    This is the result:
    Connected successfully

    [Access denied for user: 'cardini@%' to database 'articles']

    How can it connect successfully to the database, yet with the same user
    and password, fail to connect ?

    or maybe a better question would be: How did 'localhost' get changed to
    '@%' ?

  • red

    #2
    Re: Access denied for user: username@%

    red wrote:
    [color=blue]
    > I know this is probably a faq but it is hard to search for this exact
    > problem.
    > When I put this on a php page:
    > <?
    > $link = mysql_connect(" localhost", "cardini", "password")
    > or die("Could not connect : " . mysql_error());
    > echo "Connected successfully\n" ;
    > mysql_select_db ("articles") or die("Could not select database");
    >
    >
    > $sql = 'CREATE TABLE image( id mediumint( 8 ) unsigned NOT NULL
    > AUTO_INCREMENT ,'
    > . ' masterid mediumint( 8 ) unsigned NOT NULL default \'0\','
    > . ' filedata blob NOT NULL ,'
    > . ' PRIMARY KEY ( id ) ,'
    > . ' KEY master_idx( masterid ) ) TYPE = MYISAM ';
    > mysql_query($sq l);
    > db(mysql_error( ));
    > ?>
    > This is the result:
    > Connected successfully
    >
    > [Access denied for user: 'cardini@%' to database 'articles']
    >
    > How can it connect successfully to the database, yet with the same user
    > and password, fail to connect ?
    >
    > or maybe a better question would be: How did 'localhost' get changed to
    > '@%' ?
    >[/color]
    I figured out what that cryptic messge meant- the user had not been
    granted the appropriate privilege, in this case the create privilage.
    I was in the middle of granting privilages when I got distracted by the
    debate.

    Comment

    • Deon H

      #3
      Re: Access denied for user: username@%

      Hi there, Red.
      Will you please be so kind as to help me out with your solution - I have
      the same problem and I am totally new to this.

      Regards,
      Deon H

      Comment

      • red

        #4
        Re: Access denied for user: username@%

        Deon H wrote:[color=blue]
        > Hi there, Red.
        > Will you please be so kind as to help me out with your solution - I have
        > the same problem and I am totally new to this.
        >
        > Regards,
        > Deon H[/color]
        The problem confused me because my username and password successfully
        connected to the database but didn't work when I tried to create a
        table. But this does make sense because to create a table you not only
        have to have a username and password to connect to the database, you
        must have the right to create a table within that database.

        I'm using windowsxp, this is how I grant rights:

        1)Go to the command prompt. There is a link in the start menu.
        2)Change the directory to the directory of mysql. The letters cd are
        used to change the directory. On my computer, I write:
        cd c:\\mysql\bin
        The prompt changes to c:\\mysql\bin>
        3)logon to the root account of mysql . If your mysql is set up properly,
        simply typing
        mysql
        without a username and password should give you an access denied
        message. If it lets you in without giving you an access denied message,
        then you still have a default user which should be deleted.

        To access the root account type mysql -u root -p
        It will then ask you for your root password and let you in

        4) To grant rights, use the grant command. If I want to grant
        "myusername " with a password of "mypassword " the rights that most users
        are allowed to have to "mydatabase " I would use:

        grant select, insert, update, delete, index, alter, create, drop on
        mydatabase.* to myusername identified by 'mypassword';

        Notice the single quotes around the password. Those are the only quotes
        in the whole command.

        That fixed the problem for me

        Comment

        Working...