Database Settings

From OpenSimulator

(Redirected from Mysql-SVN new)
Jump to: navigation, search

If you want to quick know the walkthrough for database setup, see #Quick Setup.

TODO: This page needs to be improved for setting up database usage in Robust, though the config parameters are identical to the StandaloneCommon.ini/GridCommon.ini files.

Contents

Structure

On OpenSimulator 0.7.1 and later, you need to set StorageProvider and ConnectionString so that OpenSimulator can connect to a database. Usually you'll need to edit StandaloneCommon.ini for standalone or GridCommon.ini for grid mode.

In those files, you'll find the [DatabaseService] section. This is where the database is configured. There are number of entries - the only ones that should be uncommented (by removing the beginning semi-colon) are those which apply to the database that you want. All the others must be commented out (by adding a semi-colon to the front of the line).

Examples

MySQL

For MySQL you will uncomment the required lines and configure as appropriate. For instance, the lines

StorageProvider = "OpenSim.Data.MySQL.dll"
ConnectionString = "Data Source=localhost;Database=opensimdb;User ID=opensim;Password=h0tgrits;Old Guids=true;SslMode=None;"

In this case, it will connect to a MySQL database called opensimdb on the same machine running the simulator (localhost). The user connecting is opensim with the password h0tgrits.

PostgreSQL

For PostgreSQL you will uncomment the required lines and configure as appropriate. For instance, the lines

StorageProvider = "OpenSim.Data.PGSQL.dll"
ConnectionString = "Data Source=localhost;Database=opensimdb;User ID=opensim;Password=h0tgrits;Port=5432;"

In this case, it will connect to a PostgreSQL database called opensimdb on the same machine running the simulator (localhost). The user connecting is opensim with the password h0tgrits. If you changed the port number on PostgreSQL installation, you may add to connection string "Port=5432" where 5432 you may change to the installed port.

  • PostgreSQL database module isn't in 0.7.6 release. It is still on the bleeding edge source code.

SQLite

SQLite is slightly different. Instead you would uncomment (or leave uncommented) the line.

Or, you can include another ini files. You'll find a line like that:

Include-Storage = "config-include/storage/SQLiteStandalone.ini";

This will go on to read config-include/storage/SQLiteStandalone.ini after reading this ini file. If you open SQLiteStandalone.ini file, you'll find StrageProvider and ConnectionString lines in each sections. As SQLite does not require users or passwords to be setup, there is no further configuration to be done unless you want sqlite to use different filenames for its databases.

MSSQL

NOTE: MSSQL support will be removed in OpenSimulator 0.8.1 as it has been unmaintained for more than 2 years and so has bugs and lacks support for recent OpenSimulator features.

NOTE: There had been another way to connect to MSSQL database, which was using "mssql_connection.ini" in bin/ directory. On OpenSimulator 0.7.1 or later, it will NOT be read even if you set it properly. Use ConnectionString in *Common.ini instead. For more specific details, see the section #MSSQL.

Database Parameters

Parameter Possible Values Description
StorageProvider "OpenSim.Data.SQLite.dll" (SQLite)
"OpenSim.Data.MySQL.dll" (MySQL)
"OpenSim.Data.PGSQL.dll" (PostgreSQL)
"OpenSim.Data.MSSQL.dll" (Microsoft SQL Server)
"OpenSim.Data.Null.dll" (disable persistence)
The name of the storage provider modules, which can be found in bin/ folder. The three above are which OpenSimulator officially support (though MSSQL is partially). If you choose "OpenSim.Data.Null.dll", OpenSimulator will keep all data in its memory instead of using DBMS.
ConnectionString See #ConnectionString Syntax A string that OpenSimulator specifies information about a data source. Usually it may include the hostname or ip addresses of database server, database service names, username, schema name and password. The syntax varies between databases.
EstateConnectionString See #ConnectionString Syntax The same as ConnectionString, but it will be used only for Estate Service. (optional)

ConnectionString Syntax

MySQL

Data Source=[1];Database=[2];User ID=[3];Password=[4];Old Guids=true;

  • [1] The hostname or ip address of database server
  • [2] Database name
  • [3] Username for the database above
  • [4] Password for the user above

Example: If you have created the database "opensim" in localhost, and then created the user "opensimuser" and its password is "opensimpassword", it will be:

ConnectionString = "Data Source=localhost;Database=opensim;User ID=opensimuser;Password=opensimpassword;Old Guids=true;SslMode=None;"

PostgreSQL

Data Source=[1];Database=[2];User ID=[3];Password=[4];Port=[5]

  • [1] The hostname or ip address of database server
  • [2] Database name
  • [3] Username for the database above
  • [4] Password for the user above
  • [5] Port number for the server (default=5432)

Example: If you have created the database "opensim" in localhost, and then created the user "opensimuser" and its password is "opensimpassword", and the server port number is 5435 it will be:

ConnectionString = "Data Source=localhost;Database=opensim;User ID=opensimuser;Password=opensimpassword;Port=5435"

SQLite

URI=file:[1],version=3,UseUTF16Encoding=True;

  • [1] The path to the database file (relative to the bin/ directory - If there is no file on this path, it will be created automatically)

Example: If you want to create the database for Inventory Service in the directory "bin/db", it will be:

ConnectionString = "URI=file:db/inventory.db,version=3,UseUTF16Encoding=True"

MSSQL

Server=[1];Database=[2];User Id=[3]; password=[4];

  • [1] "servername\instance name" - You can see this string in SQL Server Managerment Studio login dialog(Server:).
  • [2] Database name
  • [3] Username for the database above
  • [4] Password for the user above

Example: If you have installed Microsoft SQL Server Express Edition with default settings on your local machine , created the database "opensim" in localhost, and then created the user "opensimuser" and its password is "opensimpassword", it will be:

ConnectionString = "Server=localhost\SQLEXPRESS;Database=opensim;User Id=opensimuser; password=opensimpassword;"

Using different database settings for different services

Note: This is extremely advanced configuration and needs to be updated for ROBUST configuration as well as standalone (which is what is implied here).

Currently there are several services in OpenSimulator.

  • [InventoryService]
  • [AssetService]
  • [AvatarService]
  • [AuthenticationService]
  • [UserAccountService]
  • [GridUserService]
  • [FriendsService]
  • [EstateDataStore]
  • [SimulationDataStore]
  • [PresenceService]
  • [AuthorizationService]
  • [GridService]

You can use a different database for each service by overriding the StorageProvider and ConnectionString properties as we saw in the general [DatabaseService] section above. For instance, if you want to use MySQL 'opensim' in general but MySQL 'opensim2' for Inventory Service and MSSQL for Authentication Service, you'll need to write in StandaloneCommon.ini something like:

[DatabaseService]
StorageProvider = "OpenSim.Data.MySQL.dll"
ConnectionString = "Data Source=localhost;Database=opensim;User ID=opensim;Password=***;Old Guids=true;SslMode=None;"
...
[InventoryService]
ConnectionString = "Data Source=localhost;Database=opensim2;User ID=opensim;Password=***;Old Guids=true;SslMode=None;"
...
[AuthenticationService]
...(another parameters for authentication service)...
StorageProvider = "OpenSim.Data.MSSQL.dll"
ConnectionString = "Data Source=(local);Database=opensim;User=opensim;password=********;"

If OpenSimulator can't find StorageProvider or ConnectionString in each service's section, it will use those in [DatabaseService] section. If OpenSimulator find each or them, it will use the parameter in each service's section. Thus, then the settings in these sections override those in [DatabaseService] section.

In this case, Inventory Service will:

  • read [DatabaseService]StorageProvider
  • read [DatabaseService]ConnectionString -> read [InventoryService]ConnectionString and override

Authentication Service will:

  • read [DatabaseService]StorageProvider -> read [AuthenticationService]StorageProvider and override
  • read [DatabaseService]ConnectionString -> read [AuthenticationService]ConnectionString and override

Note: SQLite and MSSQL providers don't support some services.

Note: For Estate Service, there is another parameter EstateConnectionString in [DatabaseService]. It is the middle priority between [DatabaseService] and [EstateDataStore] ConnectionStrings. OpenSimulator reads ConnectionString in [DatabaseService] section first, next EstateConnectionString, finally ConnectionString in [EstateDataService] section and overrides.

Quick Setup

SQLite Walkthrough

By default, OpenSimulator will automatically create its SQLite database files(*.db) in bin/ directory. You don't need to do anything generally. If you want to create the database files in another directory, you can change by editing ConnectionString in bin/config-include/storage/SQLiteStandalone.ini included by config-include/*Commons.ini. See #SQLite section for the detailed syntax.

MySQL Walkthrough

Download

Download and install "MySQL Community Server" from MySQL Downloads Page. On Linux, you can even fetch "mysql-server" or "mysql-community-server" with your native package manager.

Installing MySQL Server

On Windows: Download MSI and run it. Select "Typical". After installation, it will launch "MySQL Server Instance Configuration Wizard". Select "Standard Configuration". In the next screen, you might be happy later if you check "Include Bin Directory in Windows PATH". In the next screen, provide mysql root password. It will complete settings for mysql and startup its service automatically. See MySQL Documentation for more details.

On Mac OS X: Download DMG package and install it normally. After install the server package, you can even install MySQL Startup Item if you want MySQL to start automatically during system startup. After that, startup your MySQL by following commands. See MySQL Documentation for more details.

MySQL must be configured to use UTF8 as its default character set. In the config file /etc/my.cnf (Linux) or my.ini (Windows), add these settings:

 [mysqld]
 character-set-server=utf8

 [client]
 default-character-set=utf8

And it's ready to run.

 $ cd /usr/local/mysql
 $ sudo ./bin/mysqld_safe
 (enter your password, if necessary)
 (press ctrl-Z)
 $ bg
 (press ctrl-D or enter "exit" to exit the shell)

On Linux: RPM install the downloaded package or install "mysql-server" or "mysql-community-server" with your package manager. For more instructions for installation, see MySQL Documentation. After that, startup your MySQL with following command.

$ /etc/init.d/mysqld start

If you want to startup MySQL server automatically, see 2.10.1.2. Starting and Stopping MySQL Automatically in MySQL 5.5 Reference Manual.

Creating MySQL Database

Now you can configure your MySQL with the command line tools.

$ mysql -u root --password
(enter your password, or if you haven't set password for MySQL server, type "mysql -u root" instead)

You can even use MySQL Command Line Client on Start menu on Windows. After login, create user and database for OpenSimulator.

mysql> create database opensim;
mysql> use opensim;
mysql> create user 'opensimuser'@'localhost' identified by 'opensimpassword';
mysql> grant all on opensim.* to 'opensimuser'@'localhost';
mysql> quit

Configuring OpenSimulator

Open StandaloneCommon.ini or GridCommon.ini with your editor. First, comment-out the line for SQLite.

; SQLite
;Include-Storage = "config-include/storage/SQLiteStandalone.ini";

After that, uncomment StorageProvider and ConnectionString property lines in [DatabaseService] section and change the line like that:

; MySql
StorageProvider = "OpenSim.Data.MySQL.dll"
ConnectionString = "Data Source=localhost;Database=opensim;User ID=opensimuser;Password=opensimpassword;Old Guids=true;SslMode=None;"

Note that "Data Source=localhost;" actually specifies a TCP socket. If your MySQL server is set up to refuse remote connections (i.e. with skip-networking enabled) you'll need to replace "localhost" with the path to MySQL's UNIX socket.

ConnectionString = "Data Source=/var/run/mysqld/mysqld.lock;Database=opensim;User ID=opensimuser;Password=opensimpassword;Old Guids=true;"

You can find the path to the socket that your MySQL server is using with mysqladmin.

$ mysqladmin -p -u root version

Save and start OpenSimulator. It will access to your new MySQL database instead of the default SQLite databases.

PostgreSQL Walkthrough

Download

Download and install PostgreSQL server from PostgreSQL Downloads Page. On Linux, you can even fetch "postgresql" with your native package manager.

MSSQL Walkthrough

Download

To download Microsoft SQL Server 2008 Express edition: [1] Make sure you download Microsoft SQL Server 2008 Express with Tools ([2]) since you will likely want a nice tool to work with your database. If you already downloaded Microsoft SQL Server before, skip to "Checking Instance Configurations" step.

Installing Microsoft SQL Server

Double-click the downloaded executable and select click Installation and "New SQL Server stand-alone installation or add features to an existing installation". It will start installation process, you only need to click "OK", "Next" or "Install" until you come across the "Feature Selection". In this screen, you need to check "Database Engine Service" and "Management Tools - Basic", then click "Next". In next screen "Instance Configuration", check what is filled in "Named instance:" property - you will later use this later. For example, for default Express Edition, you'll see "SQLEXPRESS". Click "Next". Then go on default until you reach "Server Configuration". In this screen, fill in Account Name and Password field with you windows login name and password. In next "Database Engine Configuration" screen, you will need to enable Mixed Mode. After that provide password, click "Add Current User", and then continue clicking "Next" or "OK" until it completes the installation process. After that, you'll find the entry "SQL Server Managerment Studio" in "Microsoft SQL Server 2008" on the Windows Start menu. Open it and click "connect" to connect to your instance.

Checking Instance Configurations

Right-click on your database server in Management Studio and select Properties, then go to the Security tab and select SQL Server and Windows Authentication mode, click OK. If you have already installed SQL Server before and you find "Windows Authentication mode" enabled instead, change it.

Creating User for Database

Expand the Security node, then right-click the Logins node. Select "New Login..." to open "Login - New" dialog. In this screen, fill "Login name" with the string whatever you like, select "SQL Server authentication", give it a strong password, uncheck "User must change password at next login", and click "OK". In this tutorial, we'll assume you have typed "opensimuser" for Login name, and "opensimpassword" for password.

Creating Database

Right-click on the Databases node and and select "New Database..." to open "New Database" dialog. In "Database name" field, you provide any names for the new database, which we'll assume is "opensim". In "Owner" field, provide the name of newly created database user("opensimuser" in this tutorial). Accept all defaults and click "OK".

Configuring OpenSimulator

Open StandaloneCommon.ini or GridCommon.ini with your editor. First, comment-out the line for SQLite.

; SQLite
;Include-Storage = "config-include/storage/SQLiteStandalone.ini";

After that, add these line in [DatabaseService] section. As of OpenSimulator 0.7.1, there is no sample configurations for MSSQL(Microsoft SQL Server), so you need to add them by yourself.

; MSSQL
StorageProvider = "OpenSim.Data.MSSQL.dll"
ConnectionString = "Server=localhost\SQLEXPRESS;Database=opensim;User Id=opensimuser; password=opensimpassword;"

Save and start OpenSimulator. It will access to your new SQL Server database instead of the default SQLite databases.

Additional Settings

MySQL

MySQL's own configuration is handled in its my.ini file (found in "C:\ProgramData\MySQL\MySQL Server x.y" on recent versions of MySQL on Windows) or my.cnf file (found at /etc/mysql/my.cnf on Ubuntu Linux systems, for instance).

In general, the default configuration is fine for OpenSimulator. However, you may want to check the max_allowed_packet size. Very large objects, such as linksets with a very large number of parts or large mesh objects may generate OpenSimulator assets that exceed the default BLOB size that MySQL can store. On Ubuntu the max_allowed_packet size is 16M, which should be fine. On Windows MySQL it can be set larger. In early versions of MySQL the default is 1M which may be too small. Windows 5.6 MySQL default is 4M.

Notes: OSGrid maximum asset size is reported as 45MB at May 2013. Openvue grid maximum asset size is reported as 16MB as at May 2013.

To change this setting, one would add a line like the following in the [mysqld] section of the my.ini or my.cnf file. E.g.,

max_allowed_packet  = 16M

On Ubuntu 14.04.1 with MySQL latest, this setting was already found to be 16M.

The problem is that not all data is found and aborted during database recovery. Packet Too Large: mysqldump in /etc/mysql/conf.d

[mysqldump]
quick
quote-names
max_allowed_packet=2147483648

mySQL Linux Bash remote control

#!/bin/bash

### Function to query mySQL records: mysqlrest "username" "password" "databasename" "mysqlcommands"
### Return values are in the $result_mysqlrest variable
function mysqlrest()
{
	username=$1; password=$2; databasename=$3; mysqlcommand=$4;
	result_mysqlrest=$(echo "$mysqlcommand;" | MYSQL_PWD=$password mysql -u"$username" "$databasename" -N) 2> /dev/null    
}

# Example query:
username="opensim"; password="123456"; databasename="Grid";

echo "PRINT ALL DATABASE TABLES: "
mysqlrest "$username" "$password" "$databasename" "SHOW TABLES FROM $databasename"
echo "$result_mysqlrest"

# Decompose rows from one variable and write to different variables.
TABLE1=$(echo "$result_mysqlrest" | sed -n '1p')
TABLE2=$(echo "$result_mysqlrest" | sed -n '2p')
TABLE3=$(echo "$result_mysqlrest" | sed -n '3p')
#...

echo "####### TABLES 1-3 ########"
echo "TABLE1: $TABLE1"
echo "TABLE2: $TABLE2"
echo "TABLE3: $TABLE3"
#...

This is an excerpt from opensimMULTITOOL https://github.com/BigManzai/OpenSim-Shell-Script

Personal tools
General
About This Wiki