Redland RDF Library Manual |
---|
This module is compiled in when MySQL 3 or 4 is available. This store provides storage using the MySQL open source database including contexts. It was added in Redland 0.9.15. It has however been tested with several million triples and deployed.
There are several options required with the mysql storage in order to connect to the database. These are:
host
for the database server hostname
port
for the database server port (defaults to the MySQL port 3306 if not given)
database
for the MySQL database name (not the storage name)
user
for the database server user name
password
for the database server password
NOTE: Take care exposing the password as for example, program
arguments or environment variables. The rdfproc
utility can with help this by reading the password from standard
input. Inside programs, one way to prevent storing the password in a
string is to construct a Redland hash of the storage options such as
via librdf_hash_from_string
and use
librdf_new_storage_with_options
to create a storage.
The rdfproc utility source code demonstrates this.
The storage name parameter given to the storage constructor
librdf_new_storage
is used inside the mysql store to
allow multiple stores inside one MySQL database instance as
parameterised with the above options.
If boolean option new
is given, any existing MySQL
database named by the storage option database
, say
db will be dropped and the appropriate new tables created.
The MySQL database db must already exist, such as made with
the MySQL create database
db command and the
appropriate privileges set so that the user and password work.
If boolean option reconnect
is given, MySQL
reconnection will be enabled so that if the database connection
is dropped, MySQL will attempt to reconnect.
This store always provides contexts; the boolean storage option
contexts
is not checked.
Examples:
/* A new MySQL store */ storage=librdf_new_storage(world, "mysql", "db1", "new='yes',host='localhost',database='red',user='foo','password='bar'"); /* A different, existing MySQL store db2 in the same database as above */ storage=librdf_new_storage(world, "mysql", "db2", "host='localhost',database='red',user='foo','password='bar'"); /* An existing MySQL store on a different database server */ storage=librdf_new_storage(world, "mysql", "db3", "host='db.example.org',database='abc',user='baz','password='blah'"); /* Opening with an options hash */ options=librdf_new_hash(world, NULL); librdf_hash_from_string(options, "host='db.example.org',database='abc',user='baz'"); librdf_hash_put_strings(options, "password", user_password); storage=librdf_new_storage_with_options(world, "mysql", "db4", options);
In PHP:
# An existing store $storage=librdf_new_storage($world, 'mysql', 'db4', "host='127.0.0.1',database='xyz',user='foo',password='blah'");
Summary:
Persistent
Suitable for very large models
Indexed but not optimized
Smaller disk usage than BDB
Possibility of free text searching
Contexts always provided