0% found this document useful (0 votes)
43 views

Server Side Programming: by Dr. Babaousmail Hassen Lecturer at Binjiang College of NUIST

The document discusses server-side programming and MySQL commands. It covers: 1. The UPDATE command is used to modify stored data in a table by changing column values where conditions are met. 2. The DELETE command deletes rows from a table where conditions match. 3. MySQL privileges can be granted to regular users for accessing tables, administrators for server management, and special privileges like ALL for all privileges. The GRANT and REVOKE commands manage user privileges.

Uploaded by

Rifat Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Server Side Programming: by Dr. Babaousmail Hassen Lecturer at Binjiang College of NUIST

The document discusses server-side programming and MySQL commands. It covers: 1. The UPDATE command is used to modify stored data in a table by changing column values where conditions are met. 2. The DELETE command deletes rows from a table where conditions match. 3. MySQL privileges can be granted to regular users for accessing tables, administrators for server management, and special privileges like ALL for all privileges. The GRANT and REVOKE commands manage user privileges.

Uploaded by

Rifat Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Server Side Programming

By Dr. Babaousmail Hassen

Lecturer at Binjiang College of NUIST

1
Modifying Stored Data

You might like to correct a spelling mistake, or change the date


attached to a joke, such alterations are made using the UPDATE
command.

The general form of the UPDATE command is as follows:

mysql> UPDATE tableName SET


-> colName = newValue, …
-> WHERE conditions;

2
Modifying Stored Data
So, for example, if we wanted to change the date on the joke we
entered above, we have to use the following command:

mysql> UPDATE joke SET jokedate = "2010-04-01" WHERE id =


"1";

This next command, for example, changes the date of all entries that
contain
the word “chicken”:

mysql> UPDATE joke SET jokedate = "2010-04-01"


-> WHERE joketext LIKE "%chicken%";
3
Deleting Stored Data

Here’s the command syntax:

mysql> DELETE FROM tableName WHERE conditions;

To delete all chicken jokes from your table, you’d use the following
query:

mysql> DELETE FROM joke WHERE joketext LIKE "%chicken%";

4
Operator Name Example Description
(If Applicable)
= equality customerid = 3 Tests whether two values are equal
> greater than amount > 60.00 Tests whether one value is greater
than another
< less than amount < 60.00 Tests whether one value is less than
another
>= greater than or amount >= 60.00 Tests whether one value is
equal greater than or equal
to another
<= less than or equal amount <= 60.00 Tests whether one value is less than
or equal to another
!= or <> not equal quantity != 0 Tests whether two values are not
Useful IS NOT n/a address is not
equal
Tests whether field actually
contains a value
Comparison NULL
IS NULL n/a
null
address is null Tests whether field does not contain
a value
Operator for BETWEEN n/a amount between
0 and 60.00
Tests whether a value is greater
than or equal to a minimum value
and less than or equal to a maxi-
WHRE Clauses mum value
IN n/a city in Tests whether a value is in a
("Carlton", particular set
"Moe")
NOT IN n/a city not in Tests whether a value is not
("Carlton", in a set
"Moe")
LIKE pattern match name like Checks whether a value matches
("Fred %") a pattern using simple SQL pattern
matching
NOT LIKE pattern match name not like Checks whether a value doesn’t
("Fred %") match a pattern
REGEXP regular expression name regexp Checks whether a value matches a
5
regular expression
Summary of Privilege and
related Commands

Types and Levels of Privilege

Three basic types of privileges exist in MySQL:


1. Privileges suitable for granting to regular users
2. Privileges suitable for administrators, and
3. Special privileges.

6
1. Privileges for Users
Table 8.1 Privileges for Users
Privilege Applies To Description
SELECT tables, Allows users to select rows
columns (records) from tables.
INSERT tables, Allows users to insert new rows
columns into tables.
UPDATE tables, Allows users to modify values in
columns existing table rows.
DELETE tables Allows users to delete existing table rows.
INDEX tables Allows users to create and drop indexes on
particular tables.
ALTER tables Allows users to alter the structure of existing
tables by, for example, adding columns,
renaming columns or tables, and changing
data types of columns.
CREATE databases, Allows users to create new
tables databases or tables. If a
particular database or table is
specified in the GRANT, they can
only CREATE that database or table,
which means they will
have to DROP it first.
DROP databases, Allows users to drop (delete)
tables databases or tables.
7
2. Privileges for Administrators

Table 8.2 Privileges for Administrators


Privilege Description
RELOAD Allows an administrator to reload grant tables and flush privileges, hosts, logs,
and tables.
SHUTDOWN Allows an administrator to shut down the MySQL server.
PROCESS Allows an administrator to view server processes and kill them.
FILE Allows data to be read into tables from files and vice versa.

8
3. Special privileges

Table 8.3 Special Privileges


Privilege Description
ALL Grants all the privileges listed in Tables 8.1 and 8.2.You can also write ALL
PRIVILEGES instead of ALL.
USAGE Grants no privileges.This will create a user and allow her to log on, but it
won’t allow her to do anything. Usually you will go on to add more privileges
later.

9
GRANT & REVOKE Command
The GRANT command is used to give privileges to a user. The opposite of GRANT
is REVOKE. It is used to take privileges away from a user.

The general form of the GRANT command is


GRANT privileges [columns]
ON item
TO user_name [IDENTIFIED BY 'password']
[WITH GRANT OPTION]

The general form of the REVOKE command is


REVOKE privileges [(columns)] ON item
FROM user_name

10
Examples Using GRANT and
REVOKE
To set up an administrator, you can type:

mysql> grant all


-> on *
-> to fred identified by 'mnb123'
-> with grant option;

This grants all privileges on all databases to a user called Fred with the password
mnb123, and allows him to pass on those privileges.

If you don’t want this user in your system, so go ahead and revoke him:

mysql> revoke all


-> on *
-> from fred;

11
To set up a regular user with no privileges:

mysql> grant usage


-> on books.*
-> to sally identified by 'magic123';
We can give sally the appropriate privileges:
mysql> grant select, insert, update, delete, index, alter, create, drop
-> on books.*
-> to sally;
If we decide to reduce her privileges:
mysql> revoke alter, create, drop
-> on books.*
-> from sally;

And later, when she doesn’t need to use the database any more, we can revoke her
privileges:
mysql> revoke all
-> on books.*
-> from sally;
12

You might also like