Automatisation de la configuration, la création et la suppression de bases PostgreSQL et MySQL en 10 secondes seulement
Ceci est unDevOpsworkflow d'automatisation du domainecontenant 15 nœuds.Utilise principalement des nœuds comme If, Set, Ssh, ManualTrigger. Automatiser la gestion de bases de données PostgreSQL et MySQL sur un serveur Linux
- •Aucun prérequis spécial, prêt à l'emploi après importation
Nœuds utilisés (15)
Catégorie
{
"id": "OnGUB1cHxzP09UTz",
"meta": {
"instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
"templateCredsSetupCompleted": true
},
"name": "Automate PostgreSQL & MySQL Setup, Creation & Deletion in Just 10 Seconds",
"tags": [],
"nodes": [
{
"id": "f024ece1-0378-4dbb-a1b7-06bf598a04de",
"name": "Début",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-760,
480
],
"parameters": {},
"typeVersion": 1
},
{
"id": "4bd36d6f-a312-4ff2-8b6f-86a6769f2588",
"name": "Définir les paramètres",
"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": "Vérification du type de base de données",
"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": "Vérification de l'action PostgreSQL",
"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": "Vérification de l'action MySQL",
"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": "Installer 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": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "43acaf1f-beec-4d5d-9292-139626d04b05",
"name": "Installer 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": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "5315c681-2677-441b-8010-f7a742849b83",
"name": "Vérification de création PostgreSQL",
"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": "Vérification de création MySQL",
"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": "Créer la base de données PostgreSQL",
"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": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "aada1dd3-d236-4fe9-8ced-02d1ea20ef46",
"name": "Créer la base de données MySQL",
"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": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "a77b9367-1eec-40c9-b636-9bd7535ecf7a",
"name": "Supprimer la base de données PostgreSQL",
"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": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "37b5c6e2-94f6-440f-b32d-6454e5178bfc",
"name": "Supprimer la base de données MySQL",
"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": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
"name": "Formater la sortie",
"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": "Note adhésive",
"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,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "a13a1931-c209-4f37-ab8c-bdc3c35b8fd4",
"connections": {
"f024ece1-0378-4dbb-a1b7-06bf598a04de": {
"main": [
[
{
"node": "4bd36d6f-a312-4ff2-8b6f-86a6769f2588",
"type": "main",
"index": 0
}
]
]
},
"43acaf1f-beec-4d5d-9292-139626d04b05": {
"main": [
[
{
"node": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
"type": "main",
"index": 0
}
]
]
},
"4bd36d6f-a312-4ff2-8b6f-86a6769f2588": {
"main": [
[
{
"node": "8d23250e-4538-4b64-8fa4-a5cdabadc6ac",
"type": "main",
"index": 0
}
]
]
},
"aada1dd3-d236-4fe9-8ced-02d1ea20ef46": {
"main": [
[
{
"node": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
"type": "main",
"index": 0
}
]
]
},
"37b5c6e2-94f6-440f-b32d-6454e5178bfc": {
"main": [
[
{
"node": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
"type": "main",
"index": 0
}
]
]
},
"b4d41f1b-8d44-4725-87d6-72dd5d48d81a": {
"main": [
[
{
"node": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
"type": "main",
"index": 0
}
]
]
},
"bad68834-e9b1-406e-8a25-4a82d845b9eb": {
"main": [
[
{
"node": "43acaf1f-beec-4d5d-9292-139626d04b05",
"type": "main",
"index": 0
}
],
[
{
"node": "1fe28fb8-1dd9-488d-a7cf-bc47658d745e",
"type": "main",
"index": 0
}
]
]
},
"1fe28fb8-1dd9-488d-a7cf-bc47658d745e": {
"main": [
[
{
"node": "aada1dd3-d236-4fe9-8ced-02d1ea20ef46",
"type": "main",
"index": 0
}
],
[
{
"node": "37b5c6e2-94f6-440f-b32d-6454e5178bfc",
"type": "main",
"index": 0
}
]
]
},
"8d23250e-4538-4b64-8fa4-a5cdabadc6ac": {
"main": [
[
{
"node": "f49751e8-cc9c-45bc-b677-c11919054be2",
"type": "main",
"index": 0
}
],
[
{
"node": "bad68834-e9b1-406e-8a25-4a82d845b9eb",
"type": "main",
"index": 0
}
]
]
},
"b65b1c99-ec5b-486c-8513-0b20ad54186e": {
"main": [
[
{
"node": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
"type": "main",
"index": 0
}
]
]
},
"a77b9367-1eec-40c9-b636-9bd7535ecf7a": {
"main": [
[
{
"node": "e23dbe7f-2bb3-4ba2-848a-e85688a05124",
"type": "main",
"index": 0
}
]
]
},
"f49751e8-cc9c-45bc-b677-c11919054be2": {
"main": [
[
{
"node": "b4d41f1b-8d44-4725-87d6-72dd5d48d81a",
"type": "main",
"index": 0
}
],
[
{
"node": "5315c681-2677-441b-8010-f7a742849b83",
"type": "main",
"index": 0
}
]
]
},
"5315c681-2677-441b-8010-f7a742849b83": {
"main": [
[
{
"node": "b65b1c99-ec5b-486c-8513-0b20ad54186e",
"type": "main",
"index": 0
}
],
[
{
"node": "a77b9367-1eec-40c9-b636-9bd7535ecf7a",
"type": "main",
"index": 0
}
]
]
}
}
}Comment utiliser ce workflow ?
Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.
Dans quelles scénarios ce workflow est-il adapté ?
Intermédiaire - DevOps
Est-ce payant ?
Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.
Workflows recommandés
Oneclick AI Squad
@oneclick-aiThe AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.
Partager ce workflow