7.1.5 SQL Snippets tab

The Snippets tab includes built-in, local, and shared custom snippets. The My Snippets tab stores custom snippets in a file under the MySQL Workbench user's configuration directory. Select the Shared option for shared snippets.

Using Snippets

Snippets can be inserted into the SQL editor or the system's clipboard. To insert (use) a snippet, either use the snippet icons or right-click on the desired snippet and choose Insert.

Figure 7.4 SQL Snippets: Usage

SQL Snippets: Usage

Local Snippets (My Snippets)

Local snippets are stored in the MySQL Workbench user's directory. By default, the "My Snippets" SQL snippets are stored here:

Table 7.1 Default Local Snippet File Location

Operating SystemFile Path
Windows%AppData%\MySQL\Workbench\User Snippets.txt
OS X~username/Library/Application Support/MySQL/Workbench/snippets/User Snippets.txt
Linux~username/.mysql/workbench/snippets/User Snippets.txt

Editing (or adding) snippets to "My Snippets" in MySQL Workbench edits this plain text file. Optionally, you can edit this file outside of MySQL Workbench or create new files that will also be listed under the snippets selector. For example, adding a file named "More Snippets.txt" will add a "More Snippets" section to the snippets selection box.

Shared Snippets

Shared snippets are saved in a .mysqlworkbench schema on the connected MySQL server. Selecting "Shared" for the first time will request permission for MySQL Workbench to create this shared .mysqlworkbench schema. Users connected to this MySQL server are allowed to create, edit, and use these shared snippets.

Note

Shared snippets were added in MySQL Workbench 6.2.0.

The .mysqlworkbench schema is hidden from within MySQL Workbench as it is considered an internal schema that does not need to be seen or edited.

Built-in Snippets

Several built-in SQL snippets are bundled with MySQL Workbench, and typically show the SQL syntax for MySQL operations. They are divided up into the following categories.

  • DB Mgmt (Database Management): Syntax examples use SHOW in many forms to provide information about databases, tables, columns, or status information about the MySQL server.

  • SQL DDL (SQL Data Definition Language): Syntax examples include creating, altering, and dropping tables, indexes, views, and procedures.

  • SQL DML (SQL Data Manipulation Language): Syntax examples for operations such as SELECT, INSERT, and REPLACE.

The built-in operations are stored in text files in the same directory as the custom snippet files.

Saving and Editing Snippets

To save a snippet, choose the Snippets Insert icon ( ) or right-click in the snippet window and choose Add Snippet from Editor Content from the context-menu. Double-click a snippet to open it, and choose the snippet editor to edit its body or title. This example shows two snippets with only the first having defined a name.

Figure 7.5 SQL Snippets: Editor

SQL Snippets: Editor