Run a query
To run a query, create a new or open an existing SQL file, connect it to a data source, and run your code. In the Services tool window, you can view data sources (1), connection sessions (2), and attached files (3). The small green light indicates that you are connected to a data source.
Run statements from an opened file
In PhpStorm, you can open and run an SQL file. Limitation for the SQL file size is 20 MB. When you open a file that is larger than 20 MB, you see only first 2.5 MB of the file.
Open the Project tool window (View | Tool Windows | Project) and double-click an SQL file.
Click the statement that you want to execute. To run a selection of several statements, select (highlight) the statements.
Press Ctrl+Enter or select Execute from the context menu.
(Optional) If the SQL file is not connected to a data source, select or create a connection session in the Sessions window. For more information about sessions, see Managing connection sessions.
In the Statements window, press Enter to run the selected statement. You can switch between other entries to run another set of statements. Statements that you are going to execute are highlighted in the editor.
Run an SQL file from a hard drive
In the Database tool window ( ), right-click a data source.
Select Run SQL Script.
In the Select Path window, navigate to the SQL file that you want to apply.
Run an SQL file for several data sources
In the Project tool window ( ), select the SQL file that you want to run.
Right-click the SQL file, select Run <file_name> (or press Ctrl+Shift+F10).
In the Execution target window, select the necessary data sources or schemes.
Execute statements in a database console
When you create a data source, a database console is created automatically. For more information about database consoles, see Database consoles.
In the Database tool window (View | Tool Windows | Database), click the data source.
Open F4 or create (Ctrl+Shift+F10 | New Console) a database console. For more information about working with consoles, see Working with consoles.
Type or paste the statement that you want to execute.
Press Ctrl+Enter. Alternatively, click the Execute icon on the toolbar.
If you have several statements, select whether you want to execute all statements or a single statement. The suggestion list always contains an item for running all the statements.
Managing connection sessions
Create a connection session to a data source
Click the <session> list and select New session.
Attach to an existing connection session
Click the <session> list and select an existing session.
Detach a connection session
Click the <session_name> list and select an existing session.
Rename a connection session
In the Services tool window, right-click a session and select Rename Session.
Move a session or a data source to a separate tab
In the Services tool window, right-click a session or a data source and select Show in New Tab. To revert this action, close the separated tab.
Close all connection sessions
In the Services tool window, right-click a data source and select Close All Sessions.
Execute a file from the search dialog
Press Shift twice.
In the Search Everywhere dialog, type the filename.
Select a file by using Up and Down arrows.
Select data sources for which you want to run the file and click OK.
Create a database console
To create a console, use one of the following actions in the Database tool window ( ).
Click a data source and select.
Right-click a data source and select.
Click a data source, press Alt+Insert, and select Console.
Click a data source, press Ctrl+Shift+F10, and select New console.
Open a console
In the Project tool window ( ), navigate to , double-click a console file.
In the Database tool window, click the Jump to console icon () and select a console.
Click a data source, press F4, and select the console that you need.
Save a console as a file
In the console file, press Ctrl+Shift+S. Navigate to the directory where you want to store the file.