Home>Article>Database> How to set table as read-only in mysql

How to set table as read-only in mysql

青灯夜游
青灯夜游 Original
2022-01-04 16:03:20 5507browse

Setting method: 1. Execute the "mysql -u root -p" command and enter the password to log in to mysql; 2. Use the "use database name;" statement to select the specified database; 3. In the specified database, Use the "lock table data table name read;" statement to set the specified data table to read-only.

How to set table as read-only in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

MySQL sets the database table to read-only

1. Log in to mysql:

mysql> mysql -u root -p

2. Select database

mysql> use test; Database changed

When executing the select database statement, if the "Database changed" prompt appears, it means that the database selection is successful.

3. Set the table to read-only

mysql> lock table t_depart_info read; Query OK, 0 rows affected (0.00 sec)

Test: insert data

How to set table as read-only in mysql

Command analysis:

  • Since t_depart_info is set to read-only, data cannot be inserted into it, so the screenshot is always loading requests...

[Related recommendations :mysql video tutorial

The above is the detailed content of How to set table as read-only in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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