–MySQL create user
CREATE USER ‘xyz’@’localhost’ IDENTIFIED BY ‘pwd’;
–Grant example
GRANT select ON sakila.address TO xyz;
–User table with Primary key
CREATE TABLE users
( user_id INT NOT NULL AUTO_INCREMENT
, user_name VARCHAR(250)
, user_description VARCHAR(150)
, email VARCHAR(250)
, disable_flag VARCHAR(1)
, created_by VARCHAR(250)
, created_on timestamp
, last_updated_by VARCHAR(250)
, last_updated timestamp
, PRIMARY KEY (user_id)
);
— create unique index on a table
create unique index idx_sers_u1 on users (user_name);
–create non unique index on a table
CREATE INDEX idx_user_n3 ON user (email );
–create a view on a table
CREATE OR REPLACE VIEW users_v
AS SELECT user_id
, user_name
, user_description
, pwd
, created_by
, created_on
, last_updated_by
, last_updated
FROM adm_users;
–grant privilege to other user
GRANT SELECT , INSERT , update , delete on db.user_v to user2;