Database Server

From BaseX Documentation

Jump to: navigation, search

This step by step tutorial is part of the Getting Started Guide. It shows you how to run BaseX in client-server mode from a terminal. You can copy and paste all commands to get them running on your machine. After you finished this tutorial, you will be familiar with the basic administration of BaseX. Visit the commands section for a complete list of database commands.

Contents

[edit] Startup

First of all, please launch a Server and Client instance of BaseX: double click on the BaseX Server/Client icons, or run the basexserver and basexclient scripts. Follow this link for more information (or check out the additional command-line options).

[edit] Create a database

> CREATE DB factbook factbook.xml

factbook is the name of the database
factbook.xml is the xml file, which is used to create the database

If everything works you see the following lines:

Database 'factbook' created in 950.83 ms.
Where is the database stored?

By default, databases are stored in the BaseXData directory, which is located in your home folder. Depending on your Configuration, the location of your home folder varies. For example, on a Mac it's /Users/John, if your name is John. If you have used the Windows Installer, the directory will be named data, and reside in the application directory.

[edit] Execute a query

The XQUERY command lets you run a query.

> XQUERY //country

> RUN /Users/John/query.xq

[edit] Create a new database

Now we will create another database from the xmark.xml document.

> CREATE DB xmark xmark.xml

> OPEN xmark

> XQUERY //people/person/name

[edit] Switch the database

> XQUERY doc("factbook")//country

> OPEN factbook

> LIST

[edit] Close or delete a database

> CLOSE

> DROP DB xmark

[edit] Create a collection

What is a collection? With BaseX you can group documents into one logical collection. A collection is a database that contains two or more documents. Collections accept any type of XML documents, regardless of their structure.

Let's add the xmark.xml document to the factbook database to create a collection. The name of the original factbook database remains.

> OPEN factbook

> ADD xmark.xml

[edit] Delete a document

> DELETE xmark.xml

Make sure that the collection, which contains the xmark.xml document, is opened.

[edit] Delete a collection

Deleting a collection is the same as deleting a database.

> DROP DB factbook

[edit] Get server information

Several commands help to explore the state of a server. For a complete list, please visit the Commands Section.

> LIST

> INFO

> SHOW USERS

[edit] Backup and restore

> CREATE BACKUP factbook

> RESTORE factbook

Where is the backup-file stored?

The backup-file is stored in the database directory. The file is named factbook-timestamp.zip (db_name-timestamp.zip). To restore the database the file with the newest timestamp is taken.

[edit] See also

Standalone Mode, GUI, Getting Started, Advanced Usage

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export