Conversation with Gemini
You said Is there an Emacs package for editing MySQL tables?
Is there an Emacs package for editing MySQL tables?
Gemini said
There are a few options for editing MySQL tables in Emacs, depending on whether you want a full GUI-like interactive grid experience, raw terminal interaction, or external slice editing.
1. Clutch (Best for Direct Interactive Grid Editing)
How table editing works: It executes queries and presents the results in an interactive grid buffer.
You can stage edits (inserts, updates, deletes) directly in the results buffer, preview the execution batch, and commit changes with safe guardrails. Setup: Available via MELPA.
It relies on a helper backend package ( mysql.el) for native MySQL protocol communication.
2. Built-in sql-mode / sql-interactive-mode (Standard Command-Line Interface)
Emacs comes built-in with standard SQL support via M-x sql-mysql.
How table editing works: This provides an interactive SQL REPL buffer running the
mysqlCLI client. You make table edits by sending raw SQL queries (UPDATE,INSERT,DELETE) directly or executing them from a.sqlbuffer usingC-c C-r(send region).Setup: No installation required—just run
M-x sql-mysqland enter your connection details (host, user, password, database).
3. emacsql + catsql (Edit Table Slices as CSV)
How table editing works: You specify a table to query, edit the table rows in the Emacs buffer like text, and
emacsqlsyncs the updates back to your MySQL database automatically.Setup: Requires Python (
pip install emacsql catsql[mysql]).
Summary Recommendation:
If you want a visual grid to stage, preview, and apply row edits directly in Emacs, use Clutch.
If you prefer writing standard SQL statements, the built-in
sql-modeis already installed and ready to go.
You said Give me instructions for installing Clutch on Emacs on FreeBSD.
Give me instructions for installing Clutch on Emacs on FreeBSD.
Gemini said
To run Clutch on Emacs under FreeBSD to manage MySQL databases, you need to configure your package archives, install the Clutch core along with its MySQL protocol driver, and configure your connection.
Step 1: Configure Package Archives (MELPA)
If you haven't set up MELPA in Emacs yet, add the repository to your Emacs initialization file (~/.emacs, ~/.emacs.d/init.el, or ~/.config/emacs/init.el):
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
Evaluate the code or restart Emacs, then fetch the latest package lists:
M-x package-refresh-contents
Step 2: Install Clutch and the MySQL Backend
Clutch requires a separate backend package (mysql.el) to handle MySQL protocol operations.
Install Clutch:
PlaintextM-x package-install RET clutch RETInstall the MySQL protocol backend:
PlaintextM-x package-install RET mysql RET
(Alternatively, if using use-package, add the following to your init file):
(use-package mysql
:ensure t)
(use-package clutch
:ensure t
:after mysql)
Step 3: Configure Your MySQL Connection
Define your FreeBSD or remote MySQL connections in your init file using clutch-connection-alist:
(setq clutch-connection-alist
'(("my-freebsd-db"
:backend mysql
:host "127.0.0.1"
:port 3306
:user "db_user"
:database "my_database")))
Note on Passwords: You can pass
:password "your_password"in the connection parameters. However, leaving:passwordout is recommended; Clutch will securely attempt to look up your credentials viaauth-source(~/.authinfo.gpgorpass) or prompt you interactively when connecting.
Step 4: Connecting and Editing MySQL Tables
Run M-x clutch-connect. Select my-freebsd-db from the prompt list. Clutch opens a query console buffer.
Write a standard SQL SELECT query in the console buffer:
SELECT * FROM users;
Press C-c C-c to execute the statement under the point. The results render in a split interactive grid below.
Navigate into the grid window (C-x o).
Modify Cell: Move the point to a cell and start typing/editing directly.
Insert Row: Press
oto open a new staged row at the bottom.Delete Row: Press
dto mark a row for deletion.
Staged changes are highlighted. Press C-c C-c inside the grid to open a preview buffer displaying the generated UPDATE, INSERT, or DELETE SQL statements. Confirm the batch to commit the changes to your MySQL server.
You said Step 4 does not behave the way you describe. I don't get a query console buffer, only a confirmatio…
Step 4 does not behave the way you describe. I don't get a query console buffer, only a confirmation of connection.
Gemini said
The behavior you are seeing occurs because clutch-connect establishes the connection state asynchronously and echoes a confirmation message (e.g., [Clutch] Connected to my-freebsd-db), but does not automatically spawn a new SQL buffer by default.
Here is how to open the query console, execute SQL, and get into the row-editing grid:
Step 4 (Corrected): Connecting, Querying, and Editing
1. Open the Query Console Buffer
After running M-x clutch-connect and selecting your connection:
If you already have a
.sqlfile or SQL buffer open, Clutch attaches to that buffer.To open a dedicated Clutch query console manually, run:
PlaintextM-x clutch-query(Or
M-x clutch-open-consoledepending on your Clutch version). Select your active connection (my-freebsd-db).
2. Run a Query
In the opened SQL buffer, type your target query:
SELECT * FROM your_table_name;
With point anywhere on the SQL statement (or with the statement region highlighted), press:
C-c C-c
This sends the query to the server, splits the window, and opens the interactive result grid in a lower window.
3. Stage Your Edits in the Grid
Switch focus to the results buffer (C-x o):
Edit Cell: Position point on any value and type directly to modify it.
Insert Row: Press
oto add a new staged row at the end.Delete Row: Press
dto mark the current row for deletion.
4. Preview and Commit Changes
Modified cells and pending operations will be highlighted.
Press
C-c C-cinside the grid buffer to open the change preview.Confirm the generated
UPDATE/INSERT/DELETEstatements to execute them against MySQL.
You said I had to play around to get the console. The instructions still don't match. But now I get "row ed…
I had to play around to get the console. The instructions still don't match. But now I get "row editing unavailable E/D off". What does that mean?
Gemini said
In Clutch, the message row editing unavailable E/D off (or row identity missing: Edit/Delete disabled) means that Clutch has placed the results buffer in read-only mode because it cannot safely identify individual rows to target with standard UPDATE or DELETE SQL statements.
This safety guardrail triggers automatically under two main scenarios:
1. The Query Missing a Row Identity (Most Common)
Clutch needs a unique row identity (usually a Primary Key) in your SELECT projection to map an edit in the Emacs buffer back to a specific record in MySQL.
No Primary Key in
SELECT: If you runSELECT name, email FROM users;(leaving outid), Clutch cannot guarantee which specific row to update, so it disables editing.Fix: Make sure your
SELECTquery includes the Primary Key column(s):SQLSELECT id, name, email FROM users;
Table has no Primary Key: If the underlying database table lacks a Primary Key, Clutch treats the result set as read-only.
Fix: Add a Primary Key to the table via DDL:
SQLALTER TABLE users ADD PRIMARY KEY (id);
2. Derived, Aggregated, or Joined Result Sets
Clutch only permits live grid editing on direct single-table projections.
Aggregations / Groups: Queries using
GROUP BY,COUNT(),SUM(), orDISTINCTcannot be edited.Joins: Multi-table
JOINquery results are ambiguous for direct inline updates and will default toE/D off.Calculated Columns: Selecting alias columns like
SELECT id, price * 1.1 AS marked_up FROM products;will render the result set non-editable.
How to Enable Editing
To get row editing working, run a simple, direct selection of a table containing a primary key while explicitly selecting that key column:
SELECT * FROM your_table_name;
Once executed with C-c C-c, the E/D off indicator should clear, allowing you to edit values, stage new rows with o, or mark rows for deletion with d.
This video on
.jpg)
Gemini is AI and can make mistakes.

