Home > Database > Mysql Tutorial > How to lock and unlock database tables in MySQL database?

How to lock and unlock database tables in MySQL database?

黄舟
Release: 2017-08-01 14:15:57
Original
3185 people have browsed it

The storage engine tables supported by MySQL database perform table-level locking. Use lock tables to lock for the current thread, and unlock tables to release any locks obtained by the current thread. The following uses a specific example to illustrate the usage of lock and unlock. The specific operations are as follows:

How to lock and unlock database tables in MySQL database?

1. The first step is to create the database table writer and view the table structure. Use SQL statement:

create table writer(
wid int(10),
wno int(10),
wname varchar(20),
wsex varchar(2),
wage int(2)
);
desc writer;
Copy after login

As shown below:

How to lock and unlock database tables in MySQL database?

2. In the second step, insert five pieces of data into the database table writer, After inserting, check the data in the table, as shown in the following figure:

How to lock and unlock database tables in MySQL database?

3. The third step is to use the lock statement to lock the database table writer and use the SQL statement :

lock table writer read;
Copy after login

Make the database table read-only and not write

As shown in the figure below:

How to lock and unlock database tables in MySQL database?

4. The fourth step, in order to verify the locking effect, you can view the database table data and use the SQL statement:

select * from writer;
Copy after login

As shown below:

How to lock and unlock database tables in MySQL database?

5. The fifth step is to use the update statement to update id=5. The SQL statement is:

update writer set wname = '胡思思' where id = 5;
Copy after login

As shown in the figure below:

How to lock and unlock database tables in MySQL database?

6. The sixth step is to use unlock to unlock. The SQL statement is:

unlock tables;
Copy after login

As shown in the figure below:

How to lock and unlock database tables in MySQL database?

Notes

Proficient in using the lock and unlock commands

Understand the MySQL database locking and unlocking threads

The above is the detailed content of How to lock and unlock database tables in MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template