# SET and SET SESSION

Sets a session variable. The variable’s value remains in effect during an active connection to the database.

> **⚠️ Warning**: SingleStore recommends using the `SET SESSION` statement for session variables that are only referenced by the aggregator nodes on which the variable is set. For session variables with values that need to be propagated to leaf nodes from the aggregator nodes, use a global setting instead.&#x20;

## Syntax

```sql
SET [SESSION] variable_name = value;
SET @@SESSION.variable_name = value;
```

```sql
SET PASSWORD FOR 'username'@'host' = PASSWORD('password');
```

## Remarks

* `variable_name` is the name of the session variable.
* The `@@SESSION.variable_name` syntax is supported for compatibility with other database systems, such as MySQL.
* This command can be run on a  master or child aggregator node to set [sync variables](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/engine-variables/sync-variables.md), but otherwise must be run on the master aggregator.
* See the [engine variables overview](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/engine-variables.md) for information about other ways to set variables.
* The `SESSION` keyword is optional. Including it does not change this command’s behavior.
* `SET PASSWORD` sets the user password. See [SET PASSWORD](https://docs.singlestore.com/db/v9.1/reference/sql-reference/security-management-commands/set-password.md) topic for details.

> **⚠️ Warning**: In SingleStore, `SET NAMES`, `SET CHARSET`, and `SET CHARACTER SET` are valid syntax, but are  non-operational in SingleStore. These commands are included only for MySQL compatibility.

## Examples

The following queries set the value of the session variable `net_read_timeout` to 5000.

```sql
SET net_read_timeout = 5000;

SET @@SESSION.net_read_timeout = 5000;
```

The following query retrieves the value of the session variable `net_read_timeout`.

```sql
SELECT @@net_read_timeout;
```

Refer to [Assigning Expressions to Variables](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/engine-variables/assigning-expressions-to-variables/#section-idm4545871151977633309679676987.md) for more examples.

## Related Topics

* [Engine Variables Overview](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/engine-variables.md)
* [SET GLOBAL](https://docs.singlestore.com/db/v9.1/reference/sql-reference/operational-commands/set-global.md)

***

Modified at: May 28, 2025

Source: [/db/v9.1/reference/sql-reference/operational-commands/set-and-set-session/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/operational-commands/set-and-set-session/)

(An index of the documentation is available at /llms.txt)
