Change SQLite database mode to read-write

2019-01-22 00:59发布

How can I change an SQLite database from read-only to read-write?

When I executed the update statement, I always got:

SQL error: attempt to write a readonly database

The SQLite file is a writeable file on the filesystem.

标签: sqlite3
14条回答
啃猪蹄的小仙女
2楼-- · 2019-01-22 01:16

On Ubuntu, change the owner to the Apache group and grant the right permissions (no, it's not 777):

sudo chgrp www-data <path to db.sqlite3>
sudo chmod 664 <path to db.sqlite3>

Update

You can set the permissions for group and user as well.

sudo chown www-data:www-data <path to db.sqlite3>
查看更多
闹够了就滚
3楼-- · 2019-01-22 01:26

On Windows:

tl;dr: Try opening the file again.

Our system was suffering this problem, and it definitely wasn't a permissions issue, since the program itself would be able to open the database as writable from many threads most of the time, but occasionally (only on Windows, not on OSX), a thread would get these errors even though all the other threads in the program were having no difficulties.

We eventually discovered that the threads that were failing were only those that were trying to open the database immediately after another thread had closed it (within 3 ms). We speculated that the problem was due to the fact that Windows (or the sqlite implementation under windows) doesn't always immediately clean up up file resources upon closing of a file. We got around this by running a test write query against the db upon opening (e.g., creating then dropping a table with a silly name). If the create/drop failed, we waited for 50 ms and tried again, repeating until we succeeded or 5 seconds elapsed.

It worked; apparently there just needed to be enough time for the resources to flush out to disk.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-22 01:34

I had this problem today, too.

It was caused by ActiveSync on Windows Mobile - the folder I was working in was synced so the AS process grabbed the DB file from time to time causing this error.

查看更多
姐就是有狂的资本
5楼-- · 2019-01-22 01:34

In the project path Terminal django_project#

sudo chown django:django *
查看更多
狗以群分
6楼-- · 2019-01-22 01:34

Edit the DB: I was having problems editing the db. I ended up having to
sudo chown 'non root username' ts3server.sqlitedb
as long as it wasn't root, i could edit the file. Username is the username of my non root account.

Auto start TeamSpeak: as your non root account
crontab -e
@reboot /path to ts3server/ aka /home/ts3server/ts3server_startscript.sh start

查看更多
看我几分像从前
7楼-- · 2019-01-22 01:35

There can be several reasons for this error message:

  • Several processes have the database open at the same time (see the FAQ).

  • There is a plugin to compress and encrypt the database. It doesn't allow to modify the DB.

  • Lastly, another FAQ says: "Make sure that the directory containing the database file is also writable to the user executing the CGI script." I think this is because the engine needs to create more files in the directory.

  • The whole filesystem might be read only, for example after a crash.

  • On Unix systems, another process can replace the whole file.

查看更多
登录 后发表回答