0% found this document useful (0 votes)
17 views5 pages

Dbmslab14 15

The document demonstrates creating a new MySQL user and granting privileges to the user. It creates a database and table, inserts sample data, grants various privileges to the new user including select, insert, update on specific tables and columns. It also shows committing and rolling back transactions, using savepoints, and altering the user password. Experiments are demonstrated on transactions, savepoints and rollbacks.

Uploaded by

mindgamerz101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Dbmslab14 15

The document demonstrates creating a new MySQL user and granting privileges to the user. It creates a database and table, inserts sample data, grants various privileges to the new user including select, insert, update on specific tables and columns. It also shows committing and rolling back transactions, using savepoints, and altering the user password. Experiments are demonstrated on transactions, savepoints and rollbacks.

Uploaded by

mindgamerz101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

# check current user

select user();
# create new user
create database testdcl;
use testdcl;
# create a table
create table Emp(EMP_no int primary key, Emp_name varchar(10), Job varchar(10),
Hiredata date, Salary float, Comm Float, Depno int );
show tables;
# create a new user
create user 'user_test@localhost' identified by "Test@123";
# list users list and verify user_test exists.
select user from mysql.user;
# check what all privileges allotted by default on creating new user.
show grants for 'user_test@localhost';
# grant all privileges to new user
grant select on *.* to 'user_test@localhost';
# grant privileges to a specific table for (insert)

grant insert on testdcl.Emp to 'user_test@localhost';


# grant update privilege to a specific attribute on a table
grant update (Emp_name) on testdcl.Emp to 'user_test@localhost';
#show grants for new user
show grants for 'user_test@localhost';
#Verify
# logoff mysql and login using below command, it will prompt for password and
enter the
same password.
mysql -u 'user_test@localhost' -p
# verify user is user_test
slect user();
# list the grants
show grants for 'user_test@localhost';
# select databse and list tables
show databases;
use testdcl;
show tables;
# insert into tables
INSERT INTO Emp VALUES(1,'Steven', 'Marketing',
STR_TO_DATE('06-jan-1995', '%d-
%M-%Y'),24000, NULL,2);
select * from Emp;
# logoff mysql and login to super user,
mysql -u root -p
#change password of new user
alter user 'user_test@localhost' identified by '123456#';
# verify by logging with new password.
#logoff and login with user_test with newly modified password.
mysql -u 'user_test@localhost' -p
Experiment 1. Commit
/*
In MySQL, the statement SET autocommit=0; is used to disable the autocommit
feature. By
default, autocommit is enabled, which means that each SQL statement is
automatically
committed as a separate transaction.
*/
SET autocommit=0;

/*
Create Employee table
*/
CREATE TABLE Emp(EMP_no int primary key,

Emp_name varchar(10),
Job varchar(10),
Hiredata date,
Salary float,
Comm Float,
Depno int references Dept(department_id));

INSERT INTO Emp VALUES(1,'Steven', 'Marketing',


STR_TO_DATE('06-jan-
1995', '%d-%M-%Y'),24000, NULL,2);
INSERT INTO Emp VALUES(2,'Neena', 'FI_ACCOUNT',
STR_TO_DATE('06-feb-
1987', '%d-%M-%Y'),34000, NULL,1);
INSERT INTO Emp VALUES(3,'Lex', 'FI_MGR', STR_TO_DATE('06-
jan-1980',
'%d-%M-%Y'),240000, NULL,1);
INSERT INTO Emp VALUES(4,'Alexander', 'Sa_Rep',
STR_TO_DATE('06-jun-
1987', '%d-%M-%Y'),20000, NULL,4);
INSERT INTO Emp VALUES(5,'Bruce',
'IT_PROG',STR_TO_DATE('06-jul-1990',
'%d-%M-%Y'),24000, NULL,4);
start transaction ;
INSERT INTO Emp VALUES(6,'Jack','Clerk', STR_TO_DATE('06-
aug-
1980', '%d-%M-%Y'),240000, NULL,5);
UPDATE Emp SET Job = 'FI_MGR' where EMP_no = 6;
commit;
select * from Emp;

Experiment 2. Savepont & Rollback


SET autocommit=0;
start transaction;
update Emp set Salary = Salary + 1000 where EMP_no = 6;
# create savepoint
SAVEPOINT emp_save_point1;
INSERT INTO Emp VALUES(7,'Girish','Clerk', STR_TO_DATE('06-
aug-
1980', '%d-%M-%Y'),240000, NULL,5);
# verify Girish is added ;
select * from Emp;
# rollback
ROLLBACK TO SAVEPOINT emp_save_point1;
#commit transaction

commit;
# verify Girish is removed on rollback;
select * from Emp;
Experiment 3. Commit
SET autocommit=0;
start transaction;
update Emp set Salary = Salary + 1000 where EMP_no = 6;
# create savepoint
SAVEPOINT emp_save_point1;
INSERT INTO Emp VALUES(7,'Girish','Clerk', STR_TO_DATE('06-
aug-
1980', '%d-%M-%Y'),240000, NULL,5);
# verify Girish is added ;
select * from Emp;
#commit transaction
commit;
# verify Girish is NOT removed on rollback;
# rollback
ROLLBACK TO SAVEPOINT emp_save_point1;

Output
mysql> ROLLBACK TO SAVEPOINT emp_save_point1;
ERROR 1305 (42000): SAVEPOINT emp_save_point1 does not exist
select * from Emp;
This will list all employee including Girish, because Girish is already
commintted.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy