Running SQL-Code in Webmin : usning the "per-db" execution widget - vs. the global SQL-Widget: doable

SYSTEM INFORMATION
OS type and version Open Suse
Webmin version version 2.402

good day dear friends,

i manage my wordpresss istes on a root server - which is adminstered by my friend the installed webmin is the Webmin version 2.402

here i create for the vhosts - a db the user and all the permissions that are necessary.

what about the idea to create all the steps through the sql-statement-widget. in webmin we have such a widget - can i use that?

The SQL-Statements: note i am not able to use a cli - my admin did not set up such.. so i do not have the Global-SQL-Interface.

but i tested it i applied (at least some first) SQL Statements which i runned in the so called per-DB-Execution Widget.

the awesome Thing: IT works - can apply the SQL-Statement and it works

a. generates Databases
b. generates Users
etc. etx.

conclusio; i love the way using SQL-Statements and paste it directly into Webmin’s SQL widget and avoid messing up the order.

generally spoken there are some differences - in the NON-GUI way and method: the Question is : “Where to Execute SQL Globally in Webmin”?

hmm - one pathway:
i go to Servers > MySQL Database Server.
Scroll down to Global Options
Click Database Connections → inside there you should see an option for Execute SQL on server (instead of on a single database).

note: the differences some musings:

that’s the place where we can run the full SQL sequence (database + user + grants). But note i only see the “per-database SQL Editor”, i guess then i can still run CREATE DATABASE and CREATE USER there
Note: MySQL doesn’t care which DB we’re “in” when running those commands, because they’re server-wide statements. :+1:

so - i am gonna try this out Tonight: (when i am at home at the machine: )

with this SQL Template: i Guess this is a clean, reusable SQL snippet i can run in the Webmin SQL editor (global or per-database, both will work):


-- STEP 1: Create the database
CREATE DATABASE IF NOT EXISTS `__DBNAME__`
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

-- STEP 2: Create the user (replace password!)
CREATE USER IF NOT EXISTS `__DBUSER__`@'localhost'
  IDENTIFIED BY '__PASSWORD__';

-- STEP 3: Grant permissions for WordPress
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP
ON `__DBNAME__`.*
TO `__DBUSER__`@'localhost';

-- STEP 4: Apply changes
FLUSH PRIVILEGES;

How i will Use It - i will do the following

Replace DBNAME with my new database name (e.g. wp_forum).
Replace DBUSER with my new user name (e.g. wp_forum_user).
Replace PASSWORD with a strong password.

the question is: can you confirm that it is possible to run all the neceary commands through the so called “per-DB” - widget!? And that there is no General DB-Widget necesary!?

Look forwawrd to hear from you

greetings :innocent:

update: i ve added two views - of the SQL-Execution options… seee below the … view on the general SQL-Execution widget -( which is not installed (or activated) on my site here:

see the per-db-execution-widget - i have this option .. and i guess that i can run all the commands i need to run for db creations and so on.. here!?

can you confirm that!? can you confirm that here everything is possible - in SQL-creation… ?

look forward to hear from you

i was having a closer loook at the docs:

SQL commands in Webmin -
Custom Commands | Webmin
MySQL Database Server | Webmin

update2 and some more findings: found out some more inights

tip for (WordPress) admins running Webmin without CLI access:

we don’t need to rely on Webmin’s sometimes buggy GUI (refreshing very very often does not work its a pain in the ss ), to create databases and users: The per-database SQL execution widget (see the image above) can run any SQL statement, even global ones.

thats just awesome! :smiley: :star_struck:

That means we can: (/run all (!!) the SQL-commands in the per-database SQL execution widget

create databases (CREATE DATABASE ...),

create users (CREATE USER ...),

assign privileges (GRANT ... ON db.* TO user@host;),

…and verify everything with SHOW DATABASES; and SHOW GRANTS;.

This way, every WordPress site gets its own DB and user, which is much more secure than re-using accounts. Once weve learned the basic sequence, we’re independent of the GUI and fully in control.

greetings

update:

see below the cheatsheet of all the things i have tested: it may be useful for others too - so ive added this here.

This way, every WordPress site gets its own DB and user, which is much more secure than re-using accounts. Once weve learned the basic sequence, we’re independent of the GUI and fully in control. :grinning_face_with_smiling_eyes:

:toolbox: SQL Toolbox – Quick Reference (Webmin + WordPress)

A compact bilingual cheat sheet :germany: Deutsch + :united_kingdom: English
for managing MySQL databases and users via Webmin (useful for WordPress setups).

---

## đź“‚ Databases
| 🇩🇪 Deutsch | 🇬🇧 English |
|------------|-------------|
| `SHOW DATABASES;` | `SHOW DATABASES;` |
| `CREATE DATABASE \`meinedb\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;` | `CREATE DATABASE \`mydb\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;` |
| `DROP DATABASE \`meinedb\`;` | `DROP DATABASE \`mydb\`;` |

---

## 👤 Users
| 🇩🇪 Deutsch | 🇬🇧 English |
|------------|-------------|
| `SELECT User, Host FROM mysql.user;` | `SELECT User, Host FROM mysql.user;` |
| `CREATE USER 'meinuser'@'localhost' IDENTIFIED BY 'MeinPass!';` | `CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'MyPass!';` |
| `DROP USER 'meinuser'@'localhost';` | `DROP USER 'myuser'@'localhost';` |

---

## 🔑 Permissions
| 🇩🇪 Deutsch | 🇬🇧 English |
|------------|-------------|
| `GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP ON \`meinedb\`.* TO 'meinuser'@'localhost';` | `GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP ON \`mydb\`.* TO 'myuser'@'localhost';` |
| `SHOW GRANTS FOR 'meinuser'@'localhost';` | `SHOW GRANTS FOR 'myuser'@'localhost';` |
| `FLUSH PRIVILEGES;` | `FLUSH PRIVILEGES;` |

---

## 🩺 Diagnostics
| 🇩🇪 Deutsch | 🇬🇧 English |
|------------|-------------|
| `SELECT DATABASE();` | `SELECT DATABASE();` |
| `SHOW TABLES;` | `SHOW TABLES;` |
| `DESCRIBE wp_options;` | `DESCRIBE wp_options;` |
| `SELECT table_schema, ROUND(SUM(data_length+index_length)/1024/1024,2) AS SizeMB FROM information_schema.tables GROUP BY table_schema;` | `SELECT table_schema, ROUND(SUM(data_length+index_length)/1024/1024,2) AS SizeMB FROM information_schema.tables GROUP BY table_schema;` |

---

## ⚡ WordPress Setup
| 🇩🇪 Deutsch | 🇬🇧 English |
|------------|-------------|
| `CREATE DATABASE \`wp_site\`;` | `CREATE DATABASE \`wp_site\`;` |
| `CREATE USER 'wp_site_user'@'localhost' IDENTIFIED BY 'MeinPass!';` | `CREATE USER 'wp_site_user'@'localhost' IDENTIFIED BY 'MyPass!';` |
| `GRANT ALL PRIVILEGES ON \`wp_site\`.* TO 'wp_site_user'@'localhost';` | `GRANT ALL PRIVILEGES ON \`wp_site\`.* TO 'wp_site_user'@'localhost';` |
| `FLUSH PRIVILEGES;` | `FLUSH PRIVILEGES;` |

---

## 📌 Notes
- Always **separate databases and users** (1 DB = 1 user) for WordPress – avoids conflicts and improves security.  
- Use the **per-DB SQL Execute Widget** in Webmin to run these statements step by step.  
- `FLUSH PRIVILEGES;` applies changes immediately.  
- Default WordPress privileges: `SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP`.  

---

:sparkles: With this cheat sheet you can set up and manage WordPress databases in Webmin without depending on a buggy GUI.

I don’t know exactly what this means, but if Webmin fails to create a database or user, I would suspect an OOM killer event, rather than a bug. But, if you have a lot of memory and the problem is reproducible, we’d like to know about it, with details of how to reproduce the problem. We fix bugs when we know about them.

I think most folks will be creating a new domain per application (I would be and it’s what I recommend for root-level users, which you would have to be, to do what you’re suggesting), which gives you one database and user per application in Virtualmin.

This won’t be true for domain owner users, who don’t have the necessary privileges to create a new parent domain, though…that’s kind of a quirk that falls out of the user/ownership model in Virtualmin. At some point we’ll probably separate user from domain, completely, but how that implementation would work is complicated.

Virtualmin Pro also has some more advanced database management features in the GUI, which I believe also allows new databases and user/passwords independent of the domain.

But, yes, you can certainly manage databases directly, as well, if you really want to.

1 Like

tank you dear Joe
thank you for the long and detailed answer.

i now verified that i can run lots of SQL-Statements in the “per-DB-SQL-Editor” and thats very fine,

regarding the refreshing-thing. I noiticed years ago that some manually created dbs were nt visible in the overview - but if you run a correspondand SQL statement then you see it in the list..

I noticed this years berfore - and verified it last week - while doing some tests. in other wordsL: With SQL-commands you see a whole lot more.

Dear Joe - thank you for the continued support - and yes: thank you very very much for creating Webmin. I am really happy about this.

for Virtualmin i guess i do not have enough money left (/ and beisdes this - my admin only has installed and set up Webmin.

so - if you cant fly - you have to go by feet :wink:

thanks for all - i am lovin Webmin..

have a great day.

Virtualmin GPL is free, as I have told you in response to one of your other posts. Money is not a reason to not use the right tool for the job.

1 Like

hi dear Joe,
many thanks - i did not know this. I was not aware that it is free.
i work for years with Webmin - and perhaps i ll have to talk to the Admin that takes care for the whole backend - about the reasons why we stick to Webmin if Virtualmin is more appropiate here.

Btw:_ i am going to study the featurelist of Virtualmin

Probably - (only a guess) Virtualmin is powerful and “mighty_” so that i would be able to do lots and lots of things - which would (/could) mean that there could be some security-risks … (i dunno) that my serveradmin is (triying to) avoid …

this is only a guess.

i will digg deepper into all that -
and meanwhile i will work on - with the WEbmin

keep up the great work here. - WEbmin (and virtualmin for sure ) rocks!!!

greetings

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.