Find the answer to your Linux question:
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 21
I actually tried that before too but am getting the following error... You have an error in your SQL syntax near '* TO ''@'localhost' IDENTIFIED BY 'some_pass'' at line 1 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Feb 2003
    Posts
    56

    I Tried


    I actually tried that before too but am getting the following error...

    You have an error in your SQL syntax near '* TO ''@'localhost' IDENTIFIED BY 'some_pass'' at line 1

    been searching around to try to get passed this error but no luck

  2. #12
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    Run this script, and post the output you get please.

    Also, which version of MySQL are you using?


    Code:
    <?php
    // get contents of a file into a string
    $filename = "/usr/local/something.txt";
    $handle = fopen&#40;$filename, "r"&#41;;
    $contents = fread&#40;$handle, filesize&#40;$filename&#41;&#41;;
    fclose&#40;$handle&#41;;
    
    $conn = mysql_connect&#40;"localhost", "root", "password"&#41; or die&#40;mysql_error&#40;$conn&#41;&#41;;
    
    $lines = explode&#40;"\n", $contents&#41;;
    
    foreach&#40; $lines as $username &#41;
    &#123;
    $query = "GRANT ALL PRIVILEGES ON &#123;$username&#125;.* TO '&#123;$username&#125;'@'localhost' IDENTIFIED BY 'some_pass'";
    
    echo $query . "\n";
    
    mysql_query&#40;$query, $conn&#41; or die&#40;mysql_error&#40;$conn&#41;&#41;;
    &#125;
    
    mysql_close&#40;$conn&#41;;
    ?>
    Ta,

    Jason

  3. #13
    Just Joined!
    Join Date
    Feb 2003
    Posts
    56

    This

    GRANT ALL PRIVILEGES ON testaccount1.* TO 'testaccount1'@'localhost' IDENTIFIED BY 'some_pass' GRANT ALL PRIVILEGES ON testaccount2.* TO 'testaccount2'@'localhost' IDENTIFIED BY 'some_pass' GRANT ALL PRIVILEGES ON testaccount3.* TO 'testaccount3'@'localhost' IDENTIFIED BY 'some_pass' GRANT ALL PRIVILEGES ON testaccount4.* TO 'testaccount4'@'localhost' IDENTIFIED BY 'some_pass' GRANT ALL PRIVILEGES ON testaccount5.* TO 'testaccount5'@'localhost' IDENTIFIED BY 'some_pass' GRANT ALL PRIVILEGES ON .* TO ''@'localhost' IDENTIFIED BY 'some_pass' You have an error in your SQL syntax near '* TO ''@'localhost' IDENTIFIED BY 'some_pass'' at line 1

    Running version 3.23.58-1.0

  4. #14
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    I would guess you have a blank line at the end of your file that is causing you this problem.

    This version of the script should take care of it for you:

    Code:
    <?php
    // get contents of a file into a string
    $filename = "/usr/local/something.txt";
    $handle = fopen&#40;$filename, "r"&#41;;
    $contents = fread&#40;$handle, filesize&#40;$filename&#41;&#41;;
    fclose&#40;$handle&#41;;
    
    $conn = mysql_connect&#40;"localhost", "root", "password"&#41; or die&#40;mysql_error&#40;$conn&#41;&#41;;
    
    $lines = explode&#40;"\n", $contents&#41;;
    
    foreach&#40; $lines as $username &#41;
    &#123;
        //skip username if it is less that 3 chars long...
        if&#40; strlen&#40;$username&#41; < 3 &#41;
               continue;
    
         $query = "GRANT ALL PRIVILEGES ON &#123;$username&#125;.* TO '&#123;$username&#125;'@'localhost' IDENTIFIED BY 'some_pass'";
    
         echo $query . "\n";
    
         mysql_query&#40;$query, $conn&#41; or die&#40;mysql_error&#40;$conn&#41;&#41;;
    &#125;
    
    mysql_close&#40;$conn&#41;;
    ?>
    Jason

  5. #15
    Just Joined!
    Join Date
    Feb 2003
    Posts
    56

    Script

    Worked perfectly thanks a lot you guys rock!!

  6. #16
    Just Joined!
    Join Date
    Feb 2003
    Posts
    56

    Permissions

    I checked the permissions with that last script that runs without errors but the permissions say None. but with the *.* the permissions get assigned ok. Thanks

  7. #17
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    Are you connecting to the database as the right user, and from localhost?

    eg:

    # mysql -h localhost -u username1 -psome_pass username1

    Jason

  8. #18
    Just Joined!
    Join Date
    Feb 2003
    Posts
    56

    Rights

    No im not logging in as the user, im using Webmin to check the rights that are assigned to the user. Thanks

  9. #19
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    unless you log in as that user, or you log in as root, you wont be able to access the database.

  10. #20
    Just Joined!
    Join Date
    Feb 2003
    Posts
    56

    Root

    I logged in as root using Webmin to see what permissions are assigned to the accounts that the script created but under the description it says none. But when I run the original script that had *.* the permissions show under the description in webmin?

Page 2 of 3 FirstFirst 1 2 3 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •