AutomationFlowsData & Sheets › Automate Postgresql & Mysql Database Management on Linux Servers

Automate Postgresql & Mysql Database Management on Linux Servers

ByOneclick AI Squad @oneclick-ai on n8n.io

This automated n8n workflow efficiently manages the setup, creation, and deletion of PostgreSQL and MySQL databases on a Linux server, executing tasks in approximately 10 seconds. It automates installation, configuration, and user management with support for remote access. Set…

Event trigger★★★★☆ complexity15 nodesSsh
Data & Sheets Trigger: Event Nodes: 15 Complexity: ★★★★☆ Added:

This workflow corresponds to n8n.io template #6134 — we link there as the canonical source.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "OnGUB1cHxzP09UTz",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automate PostgreSQL & MySQL Setup, Creation & Deletion in Just 10 Seconds",
  "tags": [],
  "nodes": [
    {
      "id": "f024ece1-0378-4dbb-a1b7-06bf598a04de",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -760,
        480
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "4bd36d6f-a312-4ff2-8b6f-86a6769f2588",
      "name": "Set Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        -540,
        480
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "server_host",
              "value": "={{ $json.server_host || '192.168.1.100' }}"
            },
            {
              "name": "server_user",
              "value": "{{ $json.server_user || 'root' }}"
            },
            {
              "name": "server_password",
              "value": "{{ $json.server_password || 'your_password' }}"
            },
            {
              "name": "db_type",
              "value": "={{ $json.db_type || 'postgresql' }}"
            },
            {
              "name": "action",
              "value": "={{ $json.action || 'install' }}"
            },
            {
              "name": "database_name",
              "value": "={{ $json.database_name || 'mydb' }}"
            },
            {
              "name": "db_user",
              "value": "{{ $json.db_user || 'dbuser' }}"
            },
            {
              "name": "db_password",
              "value": "{{ $json.db_password || 'dbpass123' }}"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "8d23250e-4538-4b64-8fa4-a5cdabadc6ac",
      "name": "Database Type Check",
      "type": "n8n-nodes-base.if",
      "position": [
        -320,
        480
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.db_type }}",
              "value2": "postgresql"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f49751e8-cc9c-45bc-b677-c11919054be2",
      "name": "PostgreSQL Action Check",
      "type": "n8n-nodes-base.if",
      "position": [
        -100,
        180
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.action }}",
              "value2": "install"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bad68834-e9b1-406e-8a25-4a82d845b9eb",
      "name": "MySQL Action Check",
      "type": "n8n-nodes-base.if",
      "position": [
        -100,
        780
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.action }}",
              "value2": "install"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b4d41f1b-8d44-4725-87d6-72dd5d48d81a",
      "name": "Install PostgreSQL",
      "type": "n8n-nodes-base.ssh",
      "position": [
        340,
        -20
      ],
      "parameters": {
        "command": "#!/bin/bash\n\n# Install PostgreSQL\necho \"Installing PostgreSQL...\"\napt update -y\napt install -y postgresql postgresql-contrib\n\n# Start and enable PostgreSQL\nsystemctl start postgresql\nsystemctl enable postgresql\n\n# Configure PostgreSQL\nsudo -u postgres psql -c \"ALTER USER postgres PASSWORD '{{ $json.db_password }}';\"\n\n# Configure pg_hba.conf for password authentication\nsed -i \"s/#listen_addresses = 'localhost'/listen_addresses = '*'/g\" /etc/postgresql/*/main/postgresql.conf\necho \"host all all 0.0.0.0/0 md5\" >> /etc/postgresql/*/main/pg_hba.conf\n\n# Restart PostgreSQL\nsystemctl restart postgresql\n\n# Create database and user\nsudo -u postgres createdb {{ $json.database_name }}\nsudo -u postgres psql -c \"CREATE USER {{ $json.db_user }} WITH PASSWORD '{{ $json.db_password }}';\"\nsudo -u postgres psql -c \"GRANT ALL PRIVILEGES ON DATABASE {{ $json.database_name }} TO {{ $json.db_user }};\"\n\necho \"PostgreSQL installation and setup completed!\"\necho \"Database: {{ $json.database_name }}\"\necho \"User: {{ $json.db_user }}\"\necho \"Connection: psql -h {{ $json.server_host }} -U {{ $json.db_user }} -d {{ $json.database_name }}\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "43acaf1f-beec-4d5d-9292-139626d04b05",
      "name": "Install MySQL",
      "type": "n8n-nodes-base.ssh",
      "position": [
        340,
        580
      ],
      "parameters": {
        "command": "#!/bin/bash\n\n# Install MySQL\necho \"Installing MySQL...\"\napt update -y\n\n# Set MySQL root password non-interactively\ndebconf-set-selections <<< \"mysql-server mysql-server/root_password password {{ $json.db_password }}\"\ndebconf-set-selections <<< \"mysql-server mysql-server/root_password_again password {{ $json.db_password }}\"\n\napt install -y mysql-server\n\n# Start and enable MySQL\nsystemctl start mysql\nsystemctl enable mysql\n\n# Configure MySQL for remote connections\nsed -i \"s/bind-address.*/bind-address = 0.0.0.0/g\" /etc/mysql/mysql.conf.d/mysqld.cnf\n\n# Restart MySQL\nsystemctl restart mysql\n\n# Create database and user\nmysql -u root -p{{ $json.db_password }} -e \"CREATE DATABASE {{ $json.database_name }};\"\nmysql -u root -p{{ $json.db_password }} -e \"CREATE USER '{{ $json.db_user }}'@'%' IDENTIFIED BY '{{ $json.db_password }}';\"\nmysql -u root -p{{ $json.db_password }} -e \"GRANT ALL PRIVILEGES ON {{ $json.database_name }}.* TO '{{ $json.db_user }}'@'%';\"\nmysql -u root -p{{ $json.db_password }} -e \"FLUSH PRIVILEGES;\"\n\necho \"MySQL installation and setup completed!\"\necho \"Database: {{ $json.database_name }}\"\necho \"User: {{ $json.db_user }}\"\necho \"Connection: mysql -h {{ $json.server_host }} -u {{ $json.db_user }} -p{{ $json.db_password }} {{ $json.database_name }}\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5315c681-2677-441b-8010-f7a742849b83",
      "name": "PostgreSQL Create Check",
      "type": "n8n-nodes-base.if",
      "position": [
        120,
        280
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.action }}",
              "value2": "create"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1fe28fb8-1dd9-488d-a7cf-bc47658d745e",
      "name": "MySQL Create Check",
      "type": "n8n-nodes-base.if",
      "position": [
        120,
        880
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.action }}",
              "value2": "create"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b65b1c99-ec5b-486c-8513-0b20ad54186e",
      "name": "Create PostgreSQL DB",
      "type": "n8n-nodes-base.ssh",
      "position": [
        340,
        180
      ],
      "parameters": {
        "command": "#!/bin/bash\n\n# Create PostgreSQL database\necho \"Creating PostgreSQL database: {{ $json.database_name }}\"\n\nsudo -u postgres createdb {{ $json.database_name }}\nsudo -u postgres psql -c \"CREATE USER {{ $json.db_user }} WITH PASSWORD '{{ $json.db_password }}';\"\nsudo -u postgres psql -c \"GRANT ALL PRIVILEGES ON DATABASE {{ $json.database_name }} TO {{ $json.db_user }};\"\n\necho \"PostgreSQL database created successfully!\"\necho \"Database: {{ $json.database_name }}\"\necho \"User: {{ $json.db_user }}\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "aada1dd3-d236-4fe9-8ced-02d1ea20ef46",
      "name": "Create MySQL DB",
      "type": "n8n-nodes-base.ssh",
      "position": [
        340,
        780
      ],
      "parameters": {
        "command": "#!/bin/bash\n\n# Create MySQL database\necho \"Creating MySQL database: {{ $json.database_name }}\"\n\nmysql -u root -p{{ $json.db_password }} -e \"CREATE DATABASE {{ $json.database_name }};\"\nmysql -u root -p{{ $json.db_password }} -e \"CREATE USER '{{ $json.db_user }}'@'%' IDENTIFIED BY '{{ $json.db_password }}';\"\nmysql -u root -p{{ $json.db_password }} -e \"GRANT ALL PRIVILEGES ON {{ $json.database_name }}.* TO '{{ $json.db_user }}'@'%';\"\nmysql -u root -p{{ $json.db_password }} -e \"FLUSH PRIVILEGES;\"\n\necho \"MySQL database created successfully!\"\necho \"Database: {{ $json.database_name }}\"\necho \"User: {{ $json.db_user }}\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a77b9367-1eec-40c9-b636-9bd7535ecf7a",
      "name": "Delete PostgreSQL DB",
      "type": "n8n-nodes-base.ssh",
      "position": [
        340,
        380
      ],
      "parameters": {
        "command": "#!/bin/bash\n\n# Delete PostgreSQL database\necho \"Deleting PostgreSQL database: {{ $json.database_name }}\"\n\nsudo -u postgres dropdb {{ $json.database_name }}\nsudo -u postgres psql -c \"DROP USER IF EXISTS {{ $json.db_user }};\"\n\necho \"PostgreSQL database deleted successfully!\"\necho \"Database: {{ $json.database_name }} (deleted)\"\necho \"User: {{ $json.db_user }} (deleted)\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "37b5c6e2-94f6-440f-b32d-6454e5178bfc",
      "name": "Delete MySQL DB",
      "type": "n8n-nodes-base.ssh",
      "position": [
        340,
        980
      ],
      "parameters": {
        "command": "#!/bin/bash\n\n# Delete MySQL database\necho \"Deleting MySQL database: {{ $json.database_name }}\"\n\nmysql -u root -p{{ $json.db_password }} -e \"DROP DATABASE IF EXISTS {{ $json.database_name }};\"\nmysql -u root -p{{ $json.db_password }} -e \"DROP USER IF EXISTS '{{ $json.db_user }}'@'%';\"\nmysql -u root -p{{ $json.db_password }} -e \"FLUSH PRIVILEGES;\"\n\necho \"MySQL database deleted successfully!\"\necho \"Database: {{ $json.database_name }} (deleted)\"\necho \"User: {{ $json.db_user }} (deleted)\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
      "name": "Format Output",
      "type": "n8n-nodes-base.set",
      "position": [
        560,
        480
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "result",
              "value": "={{ $json.stdout }}"
            },
            {
              "name": "status",
              "value": "success"
            },
            {
              "name": "action_performed",
              "value": "={{ $('Set Parameters').item.json.action }}"
            },
            {
              "name": "database_type",
              "value": "={{ $('Set Parameters').item.json.db_type }}"
            },
            {
              "name": "database_name",
              "value": "={{ $('Set Parameters').item.json.database_name }}"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "30cb203f-a298-41c9-b897-fc5c33178aa4",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        -20
      ],
      "parameters": {
        "width": 620,
        "height": 360,
        "content": "## Core Elements\n- **Set Parameters** - Defines server details, database type, action, and credentials\n- **Type Check** - Confirms the selected database type\n- **PostgreSQL Action Check** - Identifies the action for PostgreSQL\n- **PostgreSQL Create Check** - Validates creation conditions for PostgreSQL\n- **Install PostgreSQL** - Sets up and configures PostgreSQL\n- **Create PostgreSQL DB** - Establishes a new PostgreSQL database with user access\n- **Delete PostgreSQL DB** - Removes a PostgreSQL database and user\n- **MySQL Action Check** - Identifies the action for MySQL\n- **MySQL Create Check** - Validates creation conditions for MySQL\n- **Install MySQL** - Sets up and configures MySQL\n- **Create MySQL DB** - Establishes a new MySQL database with user access\n- **Delete MySQL DB** - Removes a MySQL database and user\n- **Format Output** - Structures the final workflow output"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a13a1931-c209-4f37-ab8c-bdc3c35b8fd4",
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Install MySQL": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Parameters": {
      "main": [
        [
          {
            "node": "Database Type Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create MySQL DB": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete MySQL DB": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Install PostgreSQL": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL Action Check": {
      "main": [
        [
          {
            "node": "Install MySQL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "MySQL Create Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL Create Check": {
      "main": [
        [
          {
            "node": "Create MySQL DB",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete MySQL DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Database Type Check": {
      "main": [
        [
          {
            "node": "PostgreSQL Action Check",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "MySQL Action Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create PostgreSQL DB": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete PostgreSQL DB": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PostgreSQL Action Check": {
      "main": [
        [
          {
            "node": "Install PostgreSQL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "PostgreSQL Create Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PostgreSQL Create Check": {
      "main": [
        [
          {
            "node": "Create PostgreSQL DB",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete PostgreSQL DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This automated n8n workflow efficiently manages the setup, creation, and deletion of PostgreSQL and MySQL databases on a Linux server, executing tasks in approximately 10 seconds. It automates installation, configuration, and user management with support for remote access. Set…

Source: https://n8n.io/workflows/6134/ — original creator credit. Request a take-down →

More Data & Sheets workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Data & Sheets

This automated n8n workflow enables the rapid setup of a complete LAMP (Linux, Apache, MySQL, PHP) stack on a Linux server, executing the entire process in approximately 10 seconds. It configures the

Ssh
Data & Sheets

idats2Supa. Uses executeCommand, postgres, ssh, supabase. Event-driven trigger; 14 nodes.

Execute Command, Postgres, Ssh +1
Data & Sheets

idats2Supa. Uses executeCommand, postgres, ssh, supabase. Event-driven trigger; 14 nodes.

Execute Command, Postgres, Ssh +1
Data & Sheets

idats2Supa. Uses executeCommand, postgres, ssh, supabase. Event-driven trigger; 14 nodes.

Execute Command, Postgres, Ssh +1
Data & Sheets

This workflow acts as a junior finance research analyst for a UK boutique M&A or corporate finance team. It listens for Slack messages, classifies the request, gathers company or market data, and prod

HTTP Request, Google Drive, Google Docs +5