Question: Sublime is awesome, but I don't know how to config to run a MySQL query on Sublime with the results being shown in CMD window or recorded to a specificed TXT file (eg. `results.txt`).

```
Mysql folder: D:\xampp\mysql\bin
Mysql infor: servername= 'localhost' _ user='root' _ pass='123' _ database= 'bt1'

```

Answer: 
For Windows user create New Build System from **Tools > Build System > New Build System...**

```
{
"cmd": ["mysql", "--default-character-set=utf8", "-u", "root", "-p[USER PASSWORD]", "-v", "-t", "YOUR_DB_NAME", "-e", "source $file"],
"selector": "source.sql"

```

}

I'm using Wamp for Windows as local server. You must specify path to mysql binaries in your Environment Variables like this **c:\wamp\bin\mysql\mysql5.6.17\bin\;**

Then open a mysql file in Sublime and press **Ctrl+B**.
I have configured Sublime to run MySQL, in 2 steps:

1) Put "C:\Program Files\MySQL\MySQL Server 5.7\bin\" directory in PATH enviroment variable from my Windows;

2) In Sublime, I clicked in Tools > Build Systems > New Build Systems and inserted:

```
{
    "cmd": ["mysql.exe", "-uMyUser", "-pMyPassword", "myDataBaseName", "-e", "source  $file_name", "-t"],
    "selector": "source.sql",
    "working_dir": "$file_path",
}

```

Ofcourse, you need to change:

* **MyUser** for your user (by default use root)
* **MyPassword** for your password (by default use blank or root)
* **MyDataBaseName** for your dataBase or use blank (if you don't declare the database name, it's important put the databasename in your SQL script)

Finnaly, I saved the file as **MySQL.sublime-build**.

To test, You can select MySQL as Build System, after to create a file with .sql extension and then user CTRL + B to run SQL directly from Sublime.