# MySQL server runs out of memory or does not start

> Fix a MySQL server on your VPS that runs out of memory or will not start by adjusting its memory settings as the root user.

Source: https://helpcenter.ruachost.com/vps/guides/mysql-server-runs-out-of-memory-or-does-not-start/

This guide explains how to fix issues when your MySQL server **runs out of memory** or **fails to start**.

## **Important**

You must have **root access** to the server to follow these procedures.

## **Problem**

When attempting to start MySQL, the server may:

- Run out of memory
- Fail to start completely

## **Resolution**

The issue can usually be resolved by **reducing MySQL’s memory usage**. Modify the `my.cnf` configuration file and restart the server.

### **Steps**

1. Open the MySQL configuration file with a text editor (`nano` or `vi`):

```
nano /etc/my.cnf
```

2. Add or modify the following lines (uncomment existing lines if necessary):

```
set-variable = max_allowed_packet=1M
set-variable = thread_stack=64K
set-variable = table_cache=4
set-variable = sort_buffer=64K
set-variable = net_buffer_length=2K
set-variable = key_buffer_size=2095104
skip-innodb
skip-networking
skip-bdb
skip-ndbcluster
```

3. Save the changes to `my.cnf`.
4. Restart the MySQL server:

- ### AlmaLinux / Fedora

```
service mysqld restart
```

- ### Debian / Ubuntu

```
service mysql restart
```

After restarting, MySQL should run with reduced memory usage, resolving startup or memory issues.
