Before you start
You need three things:
- A MySQL or MariaDB database that the computer running Waifu Bridge can reach on your network.
- A way to sign in to it as an administrator: phpMyAdmin, MySQL Workbench, Adminer, or the
mysqlcommand. - The name of the database you want to share. The examples below call it
shop.
Do not give Waifu Bridge your own account, the account your website uses, or root. Make a separate account that can only read, as shown next. It takes two minutes and it is what keeps your data safe.
Make a read-only account
A database account is allowed to do only what it has been granted. An account that is granted SELECT, the permission to read, and nothing else cannot add, change or delete anything. The database itself refuses, whatever it is asked.
With the mysql command or any SQL window
- Sign in as an administrator. On the computer that runs the database, that is usually:
In phpMyAdmin, open the SQL tab instead. In MySQL Workbench, open a new query window.mysql -u root -p - Create the account. Replace the password with a long one of your own and keep it somewhere safe:
CREATE USER 'codie_reader'@'%' IDENTIFIED BY 'choose-a-long-password'; - Give it permission to read your database, and nothing else. Replace
shopwith your database’s name:GRANT SELECT ON `shop`.* TO 'codie_reader'@'%';
That is all. There is no need to run FLUSH PRIVILEGES.
To share only some tables
Instead of step 3, grant SELECT on each table you want to share. The account then cannot see any other table at all:
GRANT SELECT ON `shop`.`orders` TO 'codie_reader'@'%';
GRANT SELECT ON `shop`.`products` TO 'codie_reader'@'%';
To share only some columns of a table
Useful when a table holds something private, such as email addresses, next to things you do want to share:
GRANT SELECT (id, name, city) ON `shop`.`customers` TO 'codie_reader'@'%';
To limit where the account can sign in from
The '%' after the account name means “from any computer”. To allow only the computer that runs Waifu Bridge, put its IP address there instead, in every line:
CREATE USER 'codie_reader'@'192.168.1.50' IDENTIFIED BY 'choose-a-long-password';
GRANT SELECT ON `shop`.* TO 'codie_reader'@'192.168.1.50';
If Waifu Bridge and the database run on the same computer, leave it as '%'. Waifu Bridge runs inside Docker, so the database does not see it as localhost.
With phpMyAdmin’s screens
- Open User accounts, then Add user account.
- User name:
codie_reader. Host name: Any host. Type a long password twice. - Leave every box under Global privileges unticked, and choose Go.
- On the next screen open Database, pick your database and choose Go.
- Tick SELECT only, and choose Go.
Check the account
Still signed in as an administrator, ask the database what the new account may do:
SHOW GRANTS FOR 'codie_reader'@'%';
You should see two lines like these, and no others:
GRANT USAGE ON *.* TO `codie_reader`@`%`
GRANT SELECT ON `shop`.* TO `codie_reader`@`%`
USAGE means “may sign in” and nothing more. If you see ALL PRIVILEGES, INSERT, UPDATE, DELETE or anything else, the account can do more than read. Remove it with DROP USER 'codie_reader'@'%'; and start again.
Waifu Bridge runs this same check each time it connects, and tells you what it found.
Connect it in the console
- Open Integrations, then Database.
- Fill in the five boxes:
Box What to type Server address The name or IP address of the computer the database runs on, such as 192.168.1.40. If it is the same computer as Waifu Bridge, type that computer’s own address on your network, notlocalhost.Port 3306, unless you changed it.Database name The one database to share, such as shop.Account name codie_readerPassword The password you chose. - Choose Save and test connection.
The screen then says This account can only read. If it says the account is able to change data, saved questions still work, but your Codie is not allowed to ask its own questions until you connect an account that can only read.
Nothing is shared yet. Your Codie can use the database only after you add a saved question or tick a table.
Add saved questions
A saved question is a lookup you prepare once. When you ask your Codie something that fits, it runs that question and reads you the answer. It cannot alter the question. This is the safest and most reliable way to share.
Each question has three parts:
| Part | Example |
|---|---|
| Name | Orders today |
| When should your Codie use it? | How many orders came in today and what they add up to |
| Query | SELECT COUNT(*) AS orders, SUM(total) AS takings FROM orders WHERE created_at >= CURDATE() |
Then you can ask: “How are orders looking today?”
Questions with a detail to fill in
Write a name with a colon in front wherever your Codie should fill something in:
SELECT name, stock FROM products WHERE name LIKE CONCAT('%', :product_name, '%')
Ask “how many blue mugs do we have?” and your Codie fills in blue mugs. Give the detail a clear name, because your Codie reads it to know what to put there. Whatever it fills in is handed to the database as a value, separately from the query, so it can never be run as SQL.
Try it
Every saved question has a Try it button that shows the first rows of the answer on the screen, exactly as your Codie would receive them. Use it after every change.
- A query must be one
SELECTstatement. Anything that would change or export data is refused when you save. - Keep answers short. A count or a handful of rows is easy to say out loud; a thousand rows is not. Your Codie receives at most 50 rows.
- You can save up to 20 questions.
Let it ask its own questions
With this switched on, your Codie works out the lookup by itself, so you can ask things you never prepared: “which customer ordered the most last month?”
- On the Database screen, under Its own questions, tick the tables it may ask about.
- Switch on Let my Codie ask its own questions and choose Save.
- Start a new conversation with your Codie.
- Your Codie sees every column of a table you tick. Leave out tables with passwords, payment details or other people’s private information, or share only some columns as shown above.
- A table you do not tick cannot be asked about, even by name. That includes tables added to the database later.
- It is more flexible than a saved question and less predictable. An AI can misread what a column means and give a wrong answer with confidence. For anything you rely on, make a saved question.
- It needs an account that can only read. With any other account the switch stays off.
How your data is kept safe
| Protection | What it does |
|---|---|
| The read-only account | The database refuses every change. This holds even if everything else failed. |
| Reading only | Waifu Bridge sends a single SELECT at a time, inside a read-only transaction, and refuses anything else before it reaches the database. |
| Only what you share | Saved questions are fixed. Its own questions can name only the tables you ticked. |
| Encrypted password | The password is stored encrypted on your computer, is never shown again, and is never given to your Codie or its AI. |
| Limits | At most 50 rows come back, long text is shortened, and a question that runs for more than a few seconds is stopped. |
| A record | Activity lists every question your Codie asked. It keeps the question, never the answer. |
What leaves your home
The answer to a question goes to your Codie, and from there to the AI service your Codie thinks with, so that it can put the answer into words. With its own questions switched on, the names of the tables you ticked and their columns go there too. Share only what you are comfortable sending to that service.
The connection between Waifu Bridge and your database is not encrypted. Keep both on your home or office network, and do not point Waifu Bridge at a database across the internet.
When it does not connect
Nothing answered at that address
- Check the address and the port.
- Many databases only listen to their own computer until told otherwise. In the database’s settings file, look for
bind-address = 127.0.0.1and change it to0.0.0.0, then restart the database. - Check that a firewall on the database’s computer allows port 3306 from the computer running Waifu Bridge.
- If both run on the same computer, use that computer’s own address on your network, such as
192.168.1.50.localhostdoes not work, because Waifu Bridge runs inside Docker.
The database refused the account name or password
- Type the password again. It is easy to copy a space with it.
- If you limited where the account can sign in from, check that the address is the one the database sees Waifu Bridge coming from.
The server has no database with that name
Check the spelling. On Linux, capital letters matter: Shop and shop are different databases.
Connected, but no tables are listed
The account can sign in but was not given permission to read. Run the GRANT SELECT line again and check it with SHOW GRANTS.
My Codie says it cannot look that up
Start a new conversation, because a Codie learns new abilities at the start of one. Then open Activity: each question that did not work is listed with the reason and what to do.