# The database table scripts

Before the server can keep [users in a database](Prefs-User-Config-SQL.md), the database needs the tables. The **Scripts** tab of the [User Config section](Prefs-User-Config.md) of Preferences has the script that makes them, once for MySQL and once for Microsoft SQL Server.

![The Scripts tab with the script for MySQL](Prefs-User-Config-Scripts/mysql.png)

| Control | What it does |
|---|---|
| **Script MySQL**, **Script MS SQL** | shows the script for that database |
| **Copy To Clipboard** | copies the whole script that is shown |

The tab is for reading and copying. Nothing on it is saved, and it does not run the script: do that with the tool of your database, logged in to the database the server will use.

## Running it

1. Make an empty database, such as `crushftp`, and an account for the server that may read and write in it.
2. Copy the script and run it in that database.
3. Go on with [Moving to a database](Prefs-User-Config-SQL.md#moving-to-a-database).

The script only makes tables. It puts no users in: those come with **Import From XML**.

## The tables

| Table | Holds | Columns |
|---|---|---|
| `USERS` | one row per user | `userid`, a number the database gives; `username`; `password`, in its stored form; `server_group`, the user connection group |
| `USER_PROPERTIES` | every setting of a user, one row each | `userid`, `prop_name`, `prop_value` |
| `INHERITANCE` | whom a user inherits from | `userid`, `inherit_username`, `sort_order`, `server_group` |
| `GROUPS` | the members of each group | `groupname`, `userid`, `server_group` |
| `VFS` | the items of a user's virtual file system | `userid`, `url`, `type`, `path`, `sort_order` |
| `VFS_PERMISSIONS` | the permissions on them | `userid`, `path`, `privs` |
| `VFS_PROPERTIES` | further settings of them | `userid`, `path`, `prop_name`, `prop_value` |
| `EVENTS5` | a user's events, one row per setting of an event | `userid`, `event_name`, `prop_name`, `prop_value` |
| `IP_RESTRICTIONS` | a user's allowed and refused addresses | `userid`, `start_ip`, `type`, `stop_ip`, `sort_order` |
| `DOMAIN_ROOT_LIST` | a user's start folder per host name | `userid`, `domain`, `path`, `sort_order` |
| `WEB_BUTTONS` | a user's buttons in the web interface | `userid`, `sql_field_key`, `sql_field_value`, `for_menu`, `for_context_menu`, `sort_order` |
| `WEB_CUSTOMIZATIONS` | a user's settings of the web interface | `userid`, `sql_field_key`, `sql_field_value`, `sort_order` |
| `MODIFIED_TIMES` | the mark by which [several servers](Prefs-User-Config-SQL.md#several-servers-on-one-database) know that something changed | `server_group`, `prop_name`, `prop_value` |

Everything hangs on `userid`: a user is the row in `USERS` plus all rows with that number in the other tables.

## The script for MySQL

It also runs on MariaDB. Three things in it are worth a look before you run it:

- **The character set is `latin1`.** Letters outside the Western European ones in user names, paths and settings are not kept as they are. If you have such names, change `latin1` to `utf8mb4` everywhere in the script first.
- **The engine is `MyISAM`.** Change it to `InnoDB` if that is what your database is run with.
- **`prop_value` of `USER_PROPERTIES` holds 2,000 characters**, and `url` and `path` of `VFS` hold 255. If your users have longer values, make these columns larger in the script.

`GROUPS` is a reserved word since MySQL 8. The script writes the name in backticks, and the server does the same in its statements for MySQL and MariaDB by itself.

## The script for Microsoft SQL Server

Its text columns are `varchar(MAX)`, so lengths are not a matter there, and `userid` of `USERS` is an identity column.

## Another database

The server talks to the database through JDBC with plain statements, all of which you can see and change on the [User Database tab](Prefs-User-Config-SQL.md#the-statements). For a database the tab has no script for, make the same thirteen tables with the same column names in the types of that database, with `userid` of `USERS` as a number the database counts up by itself.
