Announcement

Collapse
No announcement yet.

How to create new user account in MySQL?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create new user account in MySQL?

    How to create new user account in MySQL and how to assigned privileges to user account?

  • #2
    Go to Shell :

    CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
    Currently new user has no permissions to do anything with the databases.

    GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
    The asterisks in this command refer to the database and table (respectively) that they can access—this specific command allows to the user to read, edit, execute and perform all tasks across all the databases and tables.

    Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges.

    FLUSH PRIVILEGES;
    Your changes will now be in effect.

    To provide a specific user with a permission, you can use this framework:

    GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
    If you want to give them access to any database or to any table, make sure to put an asterisk (*) in the place of the database name or table name.

    Each time you update or change a permission be sure to use the Flush Privileges command.

    If you need to revoke a permission, the structure is almost identical to granting it:

    REVOKE [type of permission] ON [database name].[table name] TO ‘[username]’@‘localhost’;
    Just as you can delete databases with DROP, you can use DROP to delete a user altogether:

    DROP USER ‘demo’@‘localhost’;
    To test out your new user, log out by typing
    quit
    and log back in with this command in terminal:

    mysql -u [username]-p

    Comment


    • #3
      Open MySQL command prompt. To create a new user when host is localhost then use this command
      CREATE user 'temp_user'@'localhost' identified by 'temp_password';
      for any host use %, like this
      CREATE user 'temp_user'@'%' identified by 'temp_password';
      Once the user is created, you need to Grant some access. Use following command for this.
      GRANT SELECT,INSERT,UPDATE
      ON database_name.table_name
      TO 'temp_user'@'localhost';
      After successful execution of above query, test_user can select, insert and update in table_name (name of table) of database_name (name of database).

      Hope it will some help.

      Comment


      • #4
        To provide a specific user with a permission, you can use this framework:
        Code:
        GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
        GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

        Comment


        • #5
          Originally posted by Connor View Post
          To provide a specific user with a permission, you can use this framework:
          Code:
          GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
          GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
          Don't forget to flush privileges when you're working on users and tables!

          Comment

          Working...
          X