How to Mass Assign A Single Username & Password to Hundreds of Databases?

Discussion in 'MySQL' started by macbookmed, Nov 4, 2010.

  1. #1
    Hi

    I'm running a pretty big site and ive just created about 250 new databases using phpmyadmin . Now it seems i cant find the option to assign the username and password to all of them. Is there a SQL command to do this? I dont want to manually click on each and every one in cpanel as it's very tiring.

    Thanks in advance!
     
    macbookmed, Nov 4, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO my_user@localhost IDENTIFIED BY 'some_password';

    Run this command line. The GRANT query is what will add a user to a database/table. http://dev.mysql.com/doc/refman/5.1/en/grant.html

    Also did you create 250 databases or 250 tables? Also, creating a user with access to all tables is a security risk. It is far better to put the tables all in one database and grant only to that database.

    GRANT SELECT, INSERT, UPDATE, DELETE ON database_1.* TO my_user@localhost IDENTIFIED BY 'some_password';
     
    jestep, Nov 4, 2010 IP
  3. macbookmed

    macbookmed Peon

    Messages:
    144
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, its 259 dbs actually. Ive already did it so appreciate your reply anyway.
     
    macbookmed, Nov 4, 2010 IP