how to give permissions for the user to create a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santhanalakshmi
    New Member
    • May 2009
    • 147

    how to give permissions for the user to create a database

    I am creating a USER in ROOT :

    grant all privileges on databasename.* to username@localh ost identified by 'password';
    Now,i am logging through my username :

    mysql -u username -p
    Enter password : password

    Now, i am trying to create a database :

    mysql>create database sample;
    it showing an error :

    Access denied for user 'username'@'loc alhost' to database 'sample'
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    User will only be able to create database named databasename.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      To elaborate on mwasif's point...

      You define in your GRANT statement's ON clause which databases the user can use. Any database you do not specify will not be accessible, whether it currently exists or not.

      So, because you do:
      Code:
      GRANT ALL PRIVILEGES ON [B]databasename.*[/B] ...
      your user only has access to the database named "databasena me". Trying to create - or in any other way use - another database will fail with the error you posted.

      If you want the user to have access to another database, you will need to issue another GRANT statement for that database, or give the user global access by using the wild-card char (*).
      Code:
      GRANT ALL PRIVILEGES ON [B]*.*[/B] ...
      Be careful with this though, because it gives the user access to all databases, tables and columns, which is usually not a good idea.

      Comment

      • santhanalakshmi
        New Member
        • May 2009
        • 147

        #4
        thanks for ur reply.....if we give GRANT permissions for a user to access a particular database means then that the user cannot create a new database.Its correct na.

        we should follow,if the user want to create a new database means...

        GRANT ALL PRIVILEGES *.* .....

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          If you want a user to be able to create whatever databases he likes, then you need to go with the "ON *.*" clause, yes. Just keep in mind that this does give him access to every database on the server, regardless of who created it or when it was/will be created.

          You can, however, grant him access to databases that don't yet exist. The GRANT clause doesn't care about that. So if a user is mean to be able to create a set of tables - like say: if you are creating a user for a setup script that sets up it's own databases - then you can GRANT him access to them ahead of time.

          Comment

          Working...