username & password in sqlite3

2019-02-11 17:27发布

问题:

I am using sqlite3 in a linux machine and I am getting the database without username and password. Can I set a username and password for the same?

回答1:

No, sqlite3 databases are very lightweight systems. They need no server and all data is stored in one file. A username/password is not supported by the sqlite/sqlite3 package.

In order to achieve simplicity, SQLite has had to sacrifice other characteristics that some people find useful, such as high concurrency, fine-grained access control, a rich set of built-in functions, stored procedures, esoteric SQL language features, XML and/or Java extensions, tera- or peta-byte scalability, and so forth.

(sqlite, when to use)

However, since it's only a file you can encrypt the file with a password to protect your data.



回答2:

SQLite doesn't have a concept of username/password. It's just a single file based database.

However, on Unix you can protect your database from other users on the same machine by setting the permissions of the database file itself.

e.g. Allow only owner access

chmod 700 /path/to/sqlitedb

If it's used in a simple web application then the web application will provide the control.



回答3:

SQLite is mainly an embedded database engine, not intended to be used as a multi-user database server that would require usernames and passwords.

You can always encrypt the database file with some user-provided password/-phrase, I guess. But expecting an embedded DBMS to sport full-blown access control is too much.



回答4:

The prior answers are only partially true. You can have databases that require authentication but you'll have to compile SQLite separately from PHP.

See the SQLite User Authentication documentation for further information.