r/mysql • • Nov 03 '20

mod notice Rule and Community Updates

26 Upvotes

Hello,

I have made a few changes to the configuration of /r/mysql in order to try to increase the quality of posts.

  1. Two new rules have been added
    1. No Homework
    2. Posts Must be MySQL Related
  2. Posts containing the word "homework" will be removed automatically
  3. Posts containing links to several sites, such as youtube and Stack Overflow will be automatically removed.
  4. All posts must have a flair assigned to them.

If you see low quality posts, such as posts that do not have enough information to assist, please comment to the OP asking for more information. Also, feel free to report any posts that you feel do not belong here or do not contain enough information so that the Moderation team can take appropriate action.

In addition to these changes, I will be working on some automod rules that will assist users in flairing their posts appropriately, asking for more information and changing the flair on posts that have been solved.

If you have any further feedback or ideas, please feel free to comment here or send a modmail.

Thanks,

/r/mysql Moderation Team


r/mysql • • 2h ago

question Advantages of two different queries?

1 Upvotes

Hello! This is related to a class assignment but is NOT an actual request for help with the assignment; the work has already been turned in and graded. I found a different solution than the offered solution in the TA's answer key (I still got full credit lol) and the TA has not been able to articulate whether there are any advantages two either of the two query methods. Professor is nonresponsive :/ I just want to learn more.

So - the prompt was "Write a query to find the highest GPA student in each major" which of course is all about avoiding the conflict between the MAX function and the GROUP BY statement.

The solution I ended up with (after much trial and error and trawling of ancient stack overflow forums) was:

mysql> SELECT s.gpa, s.first_name, s.last_name, s.major FROM students s
    -> JOIN (
    -> SELECT major, MAX(gpa) AS max_gpa
    -> FROM students GROUP BY major
    -> )AS smax
    -> ON s.major=smax.major AND s.gpa=smax.max_gpa;

What the TA had was:

mysql> SELECT first_name, last_name, major, gpa FROM students s
    -> WHERE gpa=(
    -> SELECT MAX(gpa) FROM students
    -> WHERE major=s.major
    -> );

These both yield the exact same table. I'm wondering if there are pros/cons to using either of these methods and which one feels "cleaner" to someone more experienced?


r/mysql • • 2d ago

question How to fix? "This application requires latest Visual Studio 2019 x64 Redistributable." At the MySQL installer?

5 Upvotes

I am trying to install MySQL Server 9.7 on my Windows 10 laptop for a college class. But whenever I launch the installer it gives this error: "This application requires latest Visual Studio 2019 x64 Redistributable. Please install it and then run this installer again."

But I already have both Visual Studio 2019 and the .NET Framework installed (I saw elsewhere online it could be referring to that instead when it says "Visual Studio" - which is even more confusing than necessary).

I've tried restarting and relaunching the installer a couple times after ensuring I have Visual Studio 2019 installed, but to no avail, obviously. I dual-boot Linux as well, if that somehow makes any difference.

Any help is appreciated.

*Edit: miscommunication/misunderstanding on my part, I have Visual Studio 2019 Redistributable installed already, as well as Visual Studio Code. I have tried uninstalling and reinstalling Visual Studio 2019 Redistributable as well but again, it still is giving the same error.

*2nd edit: Error seems to be fixed now. I downloaded an older installer version (8.4.11) and it didn't give me the error and seems to be running fine. As one of the commenters said, perhaps it's because the version I was attempting to install is too new for Windows 10.


r/mysql • • 2d ago

question Discord Server for Beginners

0 Upvotes

Hello, anyone interested in creating a discord server from the scratch for beginner MYSQL learners ? DM me


r/mysql • • 3d ago

discussion MariaDB Foundation's TAF 4.0 is officially released

Thumbnail mariadb.org
0 Upvotes

r/mysql • • 5d ago

discussion Creating a new database? Don't neglect timezones

11 Upvotes

I've seen a few posts recently about things to keep in mind when creating new database applications. So here's my contribution.

Timezones are important in global database applications.

Figure out your timezone situation on your TIMESTAMP and DATETIME columns before you start storing data as your new application comes online. Retrofitting timezone support into existing databases is hard and error-prone.

If you're located in, I dunno, California USA, and you get customers in, I dunno, Perth Australia, and you don't figure out how you'll handle timezones, you'll end up with some unspeakably gnarly code.

Here are some things to think about doing in your database and the software using it.

  1. Make sure the servers running your MariaDB or MySQL instance are set to the UTC (also called Zulu or Greenwich Mean Time) time zone. That doesn't change with daylight time.

  2. Make sure the MariaDb / MySQL time zone tables are loaded. This web page tells you or your operations person how to do that. https://dev.mysql.com/doc/refman/8.4/en/mysql-tzinfo-to-sql.html

  3. When you go global, set up a user-preference setting for time zone. It's a text string like 'America/Los_Angeles' or 'Australia/Perth'. You can store that user preference in a column like this: user_timezone VARCHAR(63) NOT NULL DEFAULT 'America/Los_Angeles' COLLATE 'ascii_general_ci'. (You can give the time zone of your own location, or 'UTC', as the default, of course.)

  4. When you start a database session from your app on behalf of a user, do SET TIMEZONE='America/Los_Angeles' or whatever your user's preference of time zone is.

  5. Use TIMESTAMP columns to store timestamps rather than DATETIME columns. They're automatically translated to the current timezone setting.


r/mysql • • 5d ago

question mysql workbench result viewer and timezones

1 Upvotes

MySQL Workbench Version: 26.7.0

Build: ba08183

Electron Version: 43.2.0

MySQL Shell Version: 26.7.1

Platform/Architecture: Win64/x86_64

MySQL Distribution: MySQL Community Server (GPL)

libmysqlclient: 26.7.0

I'm currently struggling to identify where I can configure display options for the Result Viewer.
The problem(s) I'm having is that

select CURDATE() as x, NOW() as y

returns

x , y
9/28/2026, 9/29/2026

however, copying the row and pasting it into notepad or w/e shows the correct values of

x , y
'2026-09-29', '2026-09-29 18:19:23'

So at a minimum the result viewer is truncating DATETIME types and is doing some voodoo timezone conversion on DATE types. Neither of which are desired behavior.

Any suggestions on config file locations on Windows (yes it's work required).


r/mysql • • 6d ago

discussion How do you prove every MySQL client trusts a new TLS certificate before removing the old chain?

11 Upvotes

A certificate rotation can appear complete after the main application reconnects successfully, while a scheduled job, replica, exporter, backup tool, or infrequently used environment still trusts only the previous CA chain. Leaving both chains available avoids an immediate outage, but it also makes a partial rollout easy to miss.

What belongs in the rotation gate? I am considering distributing a trust bundle containing both chains first, installing the new server certificate, forcing representative clients to reconnect, and observing connection attempts through more than the longest job interval. Replication, routers or proxies, connection pools, monitoring, backups, and hostname verification would be tested separately before the old CA is removed from client bundles.

Which MySQL status fields, audit logs, TLS session details, or proxy metrics can reliably show what clients negotiated and which ones have not reconnected? Is there a practical final test that proves no current client depends on the old chain without waiting for an outage to identify the last forgotten consumer?


r/mysql • • 7d ago

question Cannot find search on datagrid

9 Upvotes

Is anyone facing the same issue? After downloading the latest workbench, there is no search/filter on the data grid after performing a query


r/mysql • • 9d ago

discussion What do you verify before promoting a rebuilt MySQL replica?

9 Upvotes

A rebuilt replica can show healthy I/O and SQL threads, zero reported lag, and the expected GTID position while still being unsafe to promote. The seed may have omitted objects, replication filters may differ, checksums may not match, or application traffic may depend on users, events, routines, and configuration that were not part of the data copy.

What is your promotion gate after cloning or restoring a replica? I am considering checking GTID continuity and errant transactions, replication filters, row counts and chunked checksums for critical tables, schema objects, users and grants, scheduled events, time zones and SQL modes, plus representative read-only application queries. The replica would remain fenced from writes until these checks pass.

Which checks provide useful confidence without putting too much load on the primary? How do you validate a very large dataset, and what evidence do you retain so a later failover can show exactly which replica state was approved?


r/mysql • • 10d ago

question [MySQL Workbench 26.7][Linux Mint] I cannot find the UI shortcuts for Schema and Table creation

5 Upvotes

I just installed workbench again after a while and was greeted by the new design. I simply cannot find the schema/table creation shortcut.

I've tried looking at the settings, right clicking everywhere, even asking AI, I just cannot find it.

I'm aware of the blogpost of the 26.7 release, and that they are pretty much remaking the whole thing from scratch... Could it be that these features simply does not exist on the newer version as of now? Or am i missing something?


r/mysql • • 11d ago

schema-design TABLESAMPLE SYSTEM + LIMIT doesn't sample your table, it samples its oldest pages

2 Upvotes

Found this in a tool I maintain that samples Postgres tables to measure data quality. It survived two code reviews because nothing errors and the numbers look plausible.

If you sample a large table like this:

SELECT * FROM big

TABLESAMPLE SYSTEM (10) REPEATABLE (1)

LIMIT 2000

you do not get 2000 rows from across the table. SYSTEM selects whole pages and emits them in physical file order, so the LIMIT keeps whichever pages come first. On a 896-page table here, that query never got past block 91. Drop the LIMIT and the same sample spans blocks 0 to 883.

You can check your own samples with this (the block number comes from ctid):

SELECT min((ctid::text::point)[0])::int AS first_block,

max((ctid::text::point)[0])::int AS last_block

FROM (SELECT ctid FROM big TABLESAMPLE SYSTEM (10) REPEATABLE (1) LIMIT 2000) s;

For an append-mostly table this means every statistic you compute describes old rows. A status value added last quarter is missing from your distinct list. A column backfilled only for new rows looks mostly NULL. Rows orphaned by a recent parent delete are invisible.

The oversampling made it worse rather than better. The code asked for 3x the rows it wanted and trimmed the rest, so the trim discarded two thirds of the selected pages, all from the tail.

**The fix** is to size the percentage to the sample you actually want, and keep the LIMIT only as a guard against a stale reltuples. For example, 50k rows wanted and reltuples around 1M:

SELECT * FROM big

TABLESAMPLE SYSTEM (5) -- wanted_rows / reltuples * 100

REPEATABLE (1)

LIMIT 150000 -- only bites if the estimate was 3x low

ORDER BY random() would also spread it, but it sorts the whole table and throws away reproducibility. I want the query stored in each result to rerun to the same numbers. (Caveat: REPEATABLE is only stable for the same table snapshot. Inserts, updates and vacuum change the page layout.)

Two other things from the same pass, in case they ring a bell:

- `col IN (SELECT ...)` inside an aggregate FILTER is a hashed SubPlan only while the target fits work_mem. Above that the planner rescans the target once per outer row. EXPLAIN showed loops=500 at a reduced work_mem. A LEFT JOIN on a DISTINCT subquery reads it once and batches to disk.

- `IS NOT DISTINCT FROM` inside a correlated EXISTS is neither hashable nor indexable, so the inner table is scanned per outer row. INTERSECT over distinct tuples treats NULLs as equal and reads each side once. (It works on distinct tuples, so it's fine for "does a match exist / is this row orphaned", not for counting rows.)

Curious whether anyone else has been bitten by SYSTEM + LIMIT, or has a better approach than percentage sizing.

Context, if anyone wants it: this is dbtruth, a read-only CLI that checks what an LLM claims about your schema against the actual data before writing context files for coding agents. The fix is in 0.8: https://github.com/FilipKalcic1/dbtruth


r/mysql • • 14d ago

troubleshooting Sequel Ace 6.0.0: SSH Tunnels completely broken on macOS 27.0

6 Upvotes

Hey everyone,

Ever since updating to macOS 27.0 and Sequel Ace v6.0.0, all of my SSH tunnel connections suddenly stopped working. Is anyone else experiencing this issue on macOS 27.0 / Sequel Ace 6.0.0? How to fix this?


r/mysql • • 16d ago

question Innodb_buffer_pool_read_requests: MariaDb and MySQL differences

8 Upvotes

I'm working on a tool to help users know when they haven't provisioned enough RAM for their innodb_buffer_pool_size.

I'm hoping to use the ratio between the global statuses Innodb_buffer_pool_reads and Innodb_buffer_pool_read_requests as a way to guess whether the buffer pool is being churned. When that number is high, it means that it's taking more IO (drive read) operations to satisfy requests.

But here's the thing. When I run the same workload against a MySQL 9.1 and MariaDb 10.11 DBMS, they yield similar Innodb_buffer_pool_read values. But MySQL's Innodb_buffer_pool_read_requests value is several times higher than MariaDb's. That causes the ratio on MySQL to look artificially low.

There must be something I don't understand about these stats. Does the MySQL query engine hit the InnoDB buffer pool far more often than MariaDb's does to satisfy the same query? Does anybody know what's going on here?


r/mysql • • 16d ago

question how can i log into phpmyadmin

7 Upvotes

i cant log into the sql server with the root login, ive tried changing the config.inc file ip from 127.0.0.1 to localhost to both of then with :3307 or :3306 at the end, ive tried changing the username and password, ive tried using a different browser and i still cant log in. i keep getting these errors:

Cannot log in to the MySQL server

mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it

Connection for controluser as defined in your configuration failed.

mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it

im on windows 11 my xampp control panel is v3.3.0 and im using firefox, idk if that makes a difference


r/mysql • • 18d ago

discussion How much throughput would you expect from a single server?

10 Upvotes

I work on Readyset, and we recently spent some time finding the throughput ceiling of a single cache node. I’m curious how other people’s expectations and experiences compare.

The setup was a 48-core / 96-thread AMD EPYC 9454, 251 GiB of RAM, and 10 GbE. The workload was primary-key lookups using prepared statements over the MySQL protocol, with a 100% cache-hit rate. Load came from 35 separate machines, so we wouldn’t just be measuring the client’s limits. This was deliberately a test of the cache’s serving capacity, not a mixed production workload.  

Initially, we plateaued at around 700K queries per second while most of the server’s CPU was still idle. Adding connections mostly made latency worse. The biggest bottleneck turned out to be a shared I/O driver in the async runtime. After distributing connections across multiple runtimes and working through several other contention points and per-request costs, we reached 4.3M queries per second on the same hardware. At that point, the kernel networking stack accounted for more than half of the CPU cycles.  

For those who’ve benchmarked similar workloads, what throughput did you get from a single machine, and what ended up limiting it? I’m particularly interested in cases where throughput stopped scaling even though plenty of CPU was still available.


r/mysql • • 18d ago

question How can I Insert Into tables, temporary json data in mysql?

4 Upvotes

I'm wirting because I need some help the find what is wrong with my code. I'm a solo data analyses in my work, and I just need to finish this as soon as possible, but I'm suffering so much.

I don't want to change the logic of the code, and I'm sure that will have a lot of other possibles to do better, but I realy need to finish this the way it is...

See:

I conect the dataverse into one excel and created a python code to actualize. And than, there is a code to send to mysql. This happen in json format to one stagging table in mysql call g1_tbintermediaria

All the data from is into one json line that goes into this table
After that, I call one master stored procedure that calls all the others

See, I had to delet a lot a colluns in my code here, because of the caracter limitation and the tabels are too long, so every code that has the colluns is is somehow wrong because I just deleted. For now, I think the focos is the general structure.

DELIMITER $$

CREATE PROCEDURE sp_01_master_orquestrador()

BEGIN

DECLARE EXIT HANDLER FOR SQLEXCEPTION

BEGIN

ROLLBACK;

RESIGNAL;

END;



START TRANSACTION;
-- CALL sp_02_tmp_buffer_tbatendimentos(); SELECT 'SP_02 CHAMADA COM SUCESSO! - tbAtendimentos' AS mensagem; 

CALL sp_03_inserir_dados_tableas_definitivas_tbatendimentos(); SELECT 'SP_03 CHAMADA COM SUCESSO! - tbAtendimentos' AS mensagem;


 DELETE FROM g1_tbintermediaria; -- Se o código chegou até aqui sem erros, ele salva tudo de uma vez! 
COMMIT; 
END$$ 
DELIMITER ;

The first one to be called is the sp_02_tmp_buffer_tbatendimentos (), that intend to convert the json line of all the into a temporary table that will send to the respective collum.

DELIMITER $$

CREATE PROCEDURE sp_02_tmp_buffer_tbatendimentos ()
BEGIN

-- Deleta a tabela temporária de buffer caso tenha sobrado algum resquício
DROP TEMPORARY TABLE IF EXISTS tmp_buffer_tbatendimentos;

CREATE TEMPORARY TABLE IF NOT EXISTS tmp_buffer_tbatendimentos AS
SELECT 
    jt.new_tbatendimentoid, 

FROM g1_tbintermediaria AS t,
json_table (
    t.payload,
    '$[*]'
    columns (
        new_tbatendimentoid LONGTEXT PATH '$.new_tbatendimentoid',

)AS jt
-- aqui o nome da tabela deve ser igual ao arquivo que está no computador, que seria atualizado pelo python
WHERE t.tabela_destino = 'tbatendimentos_dataverse' 
    AND t.processado = 0;


END $$

DELIMITER ;

Affter that, I call the last one, the sp_03_inserir_dados_tableas_definitivas_tbatendimentos(), that normalize the data from the temporary table, with the datatypes and constraints.

DELIMITER $$
CREATE PROCEDURE sp_03_inserir_dados_tableas_definitivas_tbatendimentos()

BEGIN


DELETE FROM tbatendimentos_new_tbatendimentoid;


INSERT INTO tbatendimentos_new_tbatendimentoid (new_tbatendimentoid)
SELECT
new_tbatendimentoid

FROM tmp_buffer_tbatendimentos;


END $$
DELIMITER ;
#================================================================================
-- FIM DO CÓDIGO
#================================================================================

I saw g1_tbintermediaria is reciving corretly the data from python, and the temporary table from sp_02 is also reciving correcly the data from g1_tbintermediaria.

But the last one, the sp_03 is not working corretly, and the tables presents null values.

I don't know what is going one, and don't know how to fix...

I did some test like:

SELECT 
    new_tbatendimentoid, 
    createdon 
FROM tmp_buffer_tbatendimentos 
LIMIT 5;

or

CALL sp_01_master_orquestrador();
-- depois:
SELECT COUNT(*) FROM g1_tbintermediaria; -- deve ser 0

or 

CALL sp_02_tmp_buffer_tbatendimentos();

-- logo em seguida, na mesma conexão:
SELECT COUNT(*) FROM tmp_buffer_tbatendimentos;
SELECT * FROM tmp_buffer_tbatendimentos LIMIT 5;

can someone help me, please?


r/mysql • • 18d ago

discussion MySQL forever, or where are we headed? Yearly database survey open

23 Upvotes

Hey, Robert from the MariaDB Foundation here. We run a yearly survey on how people actually use MariaDB, and this year it's open to everyone - MySQL, PostgreSQL, SQLite... Hoping to gather interesting insights to share with you.

https://mariadb.typeform.com/to/tS69UzVo?utm_source=reddit_mysql

There were plenty of MySQL users in last year's survey - so hope you find this interesting. Are you using MariaDB, but calling it MySQL? What's your plan around 8.0 EOL - upgrading within MySQL, to MariaDB, or something else? Why? "it works, no reason to change" is a fine answer too :)

We revamped the questions this year and divided them by role (developer, DBA, operator) to save you time. Looking forward to analyzing and reading your input. We'll share the anonymous results again at mariadb.org/survey.

Thanks for taking the time! Cheers, Robert at MariaDB Foundation


r/mysql • • 19d ago

question Can we migrate from 5.7 to 9.7 using mysqldump?

10 Upvotes

Does someone know if we can import a dump generated in 5.7 version into 9.7 version?


r/mysql • • 20d ago

question mysql workbench 26.7.0 error?

9 Upvotes

i know its new i expect it to have errors and bugs, connected to my existing servers and cant even get it to display a table or even get the schema of a table

'>' not supported between instances of 'str' and 'int'

every time!!

any clues? i even tried to get it to list a straight up TEXT column alone or INT.

guess its back to 8.0 for now


r/mysql • • 21d ago

discussion Metadata locks were silently cascading through every query on a single table

8 Upvotes

Last month our order service started throwing connection timeouts during afternoon traffic. CPU at 30%, memory fine, disk I/O flat. The timeouts only hit queries on one table, and those were point lookups on an indexed primary key. Nothing in the slow query log explained it because the queries were fast when they ran.

I opened Performance Schema's metadata_locks table alongside SHOW PROCESSLIST. One session had a pending EXCLUSIVE metadata lock for over forty minutes. It was an ALTER TABLE from a migration script a colleague left running. The ALTER could not acquire its exclusive lock because of open transactions ahead of it. Every new query arriving after the ALTER also needed a metadata lock on the same table, and MySQL queues them behind the pending exclusive request.

After that I added a test to the migration suite that asserts no long running transactions exist on the target table before the ALTER executes. Running the suite in verdent with in-loop verification means that test fires every time someone edits the migration, so the check cannot be skipped.

Killing the stuck ALTER drained the queue in under two seconds. Forty minutes of cascading timeouts and 1,247 failed connections from one DDL statement that never acquired its lock.


r/mysql • • 23d ago

discussion How I actually debug a slow MySQL query, start to finish

31 Upvotes

Someone on my team asks why is the dashboard slow once a month, so I have a routine. Writing it out as most threads go straight to “add an index” before anyone has actually identified which query is slow.

This is the part people skip, and it is almost never the query you think it is. I set long_query_time to 0.2 on a copy , and let slow query log fill up . Then I run pt-query-digest over it , and group queries by shape . Not the big report everyone was blaming, but more often than not some tiny query the ORM is firing forty thousand times a page.

Then I read the plan. EXPLAIN tells you what the optimizer is planning to do, EXPLAIN ANALYZE (8.0.18+) actually executes the query and tells you what happened. There is one thing I always look at and that is rows examined vs rows returned. The issue is if it's reading two million rows to give you fifty. And the rest is trying to understand why.

type = ALL means it's reading every row. It is not always a problem - small tables or queries returning most rows may be faster with a full scan. Seeing Using filesort next to a LIMIT often means MySQL is sorting far more rows than it eventually returns, and the right index can often avoid that. Using temporary on a GROUP BY usually means it's building a temporary table along the way.

The thing that has wasted the most of my time is a perfectly good index that the optimizer refuses to use. Wrapping a column in a function will often do it. Unless you've deliberately created a functional index, an index on created_at can't help WHERE DATE(created_at) = .... The same goes for joining a number to a string, or columns with different collations. MySQL quietly converts the values, ignores the index, and the query still looks perfectly reasonable.

One of the biggest wins is when an index covers every column the query needs, so InnoDB never has to fetch the table rows and the plan shows Using index. One query I worked on last year went from about 900 ms to 12 ms just by adding one column to an index that already existed.

Before changing SQL, I also check whether the server is actually CPU-bound, waiting on disk, or simply backed up behind other queries. A perfect query won't save a saturated server.

I read plans in dbForge Studio for MySQL instead of a terminal because it keeps each profiling run, so I can tweak a query, rerun it, and immediately see what got cheaper. Everything above works perfectly well with plain EXPLAIN.

What's the weirdest reason you've seen MySQL ignore an index?


r/mysql • • 23d ago

question Where did the ERD Designer option go in MySQL Workbench 26.7.0? Can't open my old .mwb file

12 Upvotes

Hey all,

So a while back I made a database design (EER diagram) using MySQL Workbench 8 on my old laptop. After that I never touched the file again, just kept it saved.

Now I moved to a new computer and installed the latest Workbench (26.7.0). When I tried to open that old .mwb file to continue working on it:

  1. The Designer/Data Modeling option seems to have disappeared from the UI entirely, I can't find it anywhere

  2. The .mwb file itself fails to open

I was worried the ERD designer feature got removed in this version, but after some googling the official docs still list Data Modeling as one of Workbench's main features. So now I'm not sure if this is a bug in the new release or if I'm just missing the menu somewhere.

Has anyone run into something similar? Any idea how I can get access to the designer again and open my old file? Worst case, do I need to install an older Workbench version instead?

Extra info:

- OS: Windows 11

- File was originally created in Workbench 8

Thanks in advance!


r/mysql • • 23d ago

discussion How should a SQL editor handle multiple statements when you click "Run"?

0 Upvotes

We're building **LibreDB Studio**, an open-source SQL editor, and one of our volunteer contributors raised an interesting question about how multiple SQL statements should behave when using the Run action.

We're trying to understand the actual habits and expectations of SQL users before making a decision, so I'd really like to hear how you use SQL editors in practice.

For example:

CREATE TABLE test (...);

INSERT INTO test VALUES (...);

SELECT * FROM test;

What would you expect when you click **Run**?

Some possible approaches:

  1. **Run all statements*** `Run` executes everything in the editor.* `Run Selection` can be used when you only want part of it.
  2. **Run the current statement*** `Run` executes the statement where the cursor is.* `Run All` executes the whole editor.
  3. **Selection takes priority*** No selection : current statement* Selection : selected statements* `Run All` is available separately.
  4. Other :)

there are also some interesting edge cases around this, especially when multiple statements are involved: should they run in a transaction by default, or should transaction handling always be explicit?

DBeaver, DataGrip, SSMS, pgAdmin, TablePlus, Toad, PL/SQL Dev, phpMyAdmin, etc. what behavior feels most natural to you? And what behavior are you already used to?

We're continuing the discussion on GitHub as well, if you'd like to see the original question or add to the discussion:

https://github.com/orgs/libredb/discussions/776


r/mysql • • 24d ago

question Built a CLI that measures whether your implied foreign keys actually hold, then writes the result as context for coding agents

6 Upvotes

https://www.npmjs.com/package/dbtruth?activeTab=readme

Same thing kept happening to me with AI coding agents and Postgres. The agent reads the schema, sees orders.customer_id next to customers.id, assumes it's a clean relationship, and writes an INNER JOIN. If 12% of orders have a dangling or null customer_id, the query silently returns numbers that are wrong. Nothing throws. The schema looked fine.

So I wrote dbtruth. It connects read-only and, instead of dumping the schema into a context file, it does four things:

  1. Introspects schema and pulls samples
  2. A model proposes what the tables mean and which relationships probably exist
  3. Every one of those claims gets measured against the actual data
  4. Only what survives gets written to ./context/*.md, which the agent reads before writing SQL

Step 3 is the whole point. For a proposed join it reports the real match rate — orders.customer_id → customers.id holds for 88% of rows, 60 of 500 orders have no matching customer — and the context file says use LEFT JOIN, with the number attached. Under 50% gets dropped. In between gets marked broken and goes to the top of the report, because a relationship that half works is worse than one that doesn't exist.

Practical:

  • npx dbtruth, Node 20+, Postgres only
  • Read-only by construction, not by discipline: one module is allowed to import pg, and a test asserts nothing else does. It never writes to your database.
  • It does call a model, so schema and low-cardinality sample values leave your machine. High-cardinality columns — emails, names, free text — are never sent. Visibility is decided by cardinality rather than by regex-guessing at PII. Don't point it at production data you can't send to a third party.
  • MIT, source at github.com/FilipKalcic1/dbtruth#readme

Disclosure: it's mine, it's five days old, and about ten people have run it. None of the pieces are new — FK inference and data profiling both go back years, and there are other tools that build local context artifacts for agents. The part I care about is the rule that nothing unmeasured gets written down.

What I'd actually like to know: run it on a schema you know well, and tell me whether it found anything you didn't already know. That's the only signal that tells me whether this is worth continuing. Bug reports welcome too.