[end_label]
7.2 Call stored procedures and functions
7.2.1 Call stored procedure
call proc_name([paramter[,...]])
7.2.2 Call stored procedure
select fun_name([paramter[,...]])
7.3 View stored procedures and functions
- Use the show status statement to view the status of stored procedures and functions
show {procedure|function} status{like 'pattern'}
2. Use the show create statement to view the definitions of stored procedures and functions
show create {procedure|function} proc_name
3. View stored procedure and function information from the information_schema.routine table
select * from information_schema.routine where routine_name='proc_name'
7.4 Modify stored procedures and functions
alter {procedure|function} proc_name{characteries ... };
7.5 Delete
drop procedure proc_name
drop function fun_name
trigger
SQL statements that can activate triggers: insert, delete, update
create trigger
- Create a trigger to execute a statement
create trigger trigger_name before|after trigger_event on table_name for each row trigger_simt
trigger_event: trigger the execution condition, insert delete insert
trigger_simt: the SQL statement executed after the trigger is activated - Create triggers that execute multiple statements
create trigger trigger_name before|after trigger_event on table_name for each row begin trigger_simit end
view triggers
- View through the show triggers statement
show triggers \G
2. View by viewing the system table triggers
use information_schema
select * from triggers
delete trigger
drop trigger trigger_name
Transactions and Locks
affairs
- Features: Atomicity (A), Consistency©, Isolation (I), Persistence (D).
- Redo log: When the transaction is executed, the executed transaction log needs to be written into the redo log file. When Mysql crashes, the records in the redo log will be re-executed
- Undo log: It is mainly used for data rollback when the transaction is abnormal, that is, the database content before the transaction is copied to the undo buffer, and then the content is flushed to the disk at an appropriate time.
control statement
begin: start transaction
commit: end transaction
rollback: rollback transaction
Mysql can support local transactions through set autocommit, start transaction, commit and rollback
start transaction|begin|work|commit [work][and [no] chanin] [[no] release] rollback [work] [and [no] chain] [[no] release] set autocommit ={0|1}
isolation level
A check B change
- Uncommitted read (read uncommitted) == Dirty read: After the rollback, the value of A’s query twice is different, and A can view the content of B’s modification process
- Committed to read (read committed) == non-repeatable read: A can check the modified content of B after submission, and the query data is inconsistent
- Repeatable read (repeatable read) Mysql default == phantom reading: after submitting, A cannot find the content modified by B, each is different, but A can update the content modified by B, and after the update, B’s modification can be found Content
- Serializable (serializable): the highest level, there may be a large number of timeouts and lock competition
View transaction isolation level: select @@global.tx_isolation
InnoDB lock mechanism
type of lock
- Shared lock (S): the granularity is a row or tuple (multiple rows), the lock can be acquired to perform read operations
- Exclusive lock (X): the granularity is a row or a tuple (multiple rows), and the lock can be acquired to perform write and read operations
If A has a shared lock, you cannot add an exclusive lock at the same time, you can add a shared lock at the same time
If A has an exclusive lock, you cannot add a shared lock at the same time, and you cannot add a shared lock at the same time
3. Intention lock: the granularity is the entire table
- Intent exclusive lock (IX)
- Intention shared lock (IS): Intentionally shared locks and exclusive locks on data
are either compatible or exclusive
lock granularity
- Table lock: low overhead, minimum concurrency allowed - MyISAM
- Row lock: the maximum amount of concurrency allowed, - InnoDB
eg:select ... lock in share mode
``select … for update