More Than Five
More Than Five

Reputation: 10419

Create a user that can connect to the database in H2

To create a user in H2, one does:

CREATE USER NEWUSER PASSWORD 'P';

How is it possible to create a new user that can connect to an existing database in H2?

I have tried:

GRANT ALL TO NEWUSER;

but this does not work.

Any ideas?

Upvotes: 3

Views: 9413

Answers (3)

king pong
king pong

Reputation: 327

This worked on H2 version 2.1.210:

  1. Create new user with command:

    CREATE USER newuser PASSWORD 'newpwd';
    
  2. Log in as admin (schema owner, by default it's 'sa') and get schema name:

    SELECT * FROM INFORMATION_SCHEMA.SCHEMATA; 
    

In my case the schema name was 'PUBLIC';

  1. To assign all rights to the new user, use this command:

    GRANT ALL ON SCHEMA PUBLIC TO newuser;
    
  2. Check the result, you should see newuser with RIGHTS=ALL here:

    SELECT * FROM INFORMATION_SCHEMA.RIGHTS;
    

Upvotes: 0

Lini
Lini

Reputation: 363

You can do as follows (see here):

create user if not exists scott password 'tiger' admin;

Upvotes: 7

Feijao Costa
Feijao Costa

Reputation: 11

You could try setting user as administrator:

ALTER USER TOM ADMIN TRUE

Upvotes: 1

Related Questions