Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
sqlite> DELETE FROM mails WHERE (`id` = 71);
SQL error: database is locked

How can I unlock the database so this would work? 

1 Answer

0 votes
by (12.7k points)
edited by

First create a backup of the database, which will have no locks on it.

Then after, replace the database with its backup copy. 

Follow the latter script to do the same where .x.Sqlite is the Sqlite database file:

$Sqlite3 .x.Sqlite

Sqlite> .backup main backup.Sqlite

Sqlite> .exit

Want to learn about databases in depth? Here is the Database Training Course provided by Intellipaat.

Further, you will have a file named backup.Sqlite in the corresponding directory. Then you will have to swap your old database with the backup copy of the database. Thus, the backup copy does not have any locks in it, the SQLite database is locked error code 5 will not be conflicted.

$mv .x.Sqlite old.Sqlite

$mv backup.Sqlite .x.Sqlite

After the successful execution of the above script, you can moreover access the SQLite database. Review that the database is allowing both the read and write operations to run successfully, and then you can delete the old SQLite database file.

Want to be a SQL expert? Come and join this SQL Certification course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...