当前位置:网站首页>Pycharm database tool
Pycharm database tool
2022-06-30 04:55:00 【Calvin klenin】
PyCharm Database tools
In the process of software development , Is inseparable from the database ,PyCharm It provides rich functions for operating the database , You can leave without PyCharm IDE Connect to different types of databases under the environment of , Executable SQL Script 、 View results, export and import data and other functions , This course will introduce these common functions in PyCharm in How to use . You should have the basic knowledge of database after learning this chapter .
1. Database Tools and SQL
PyCharm The database management function in is provided by Database Toools and SQL Plug in support . The plug-in supports DataGrip All the functions provided in (DataGrip It is an independent database management environment for developers , It's also JetBrains Products of the company ): Support query 、 Create and manage various types of databases , Include MySQL、PostgreSQL、SQL Server、SQLite、MariaDB、Oracle、Apache Cassandra wait , The database can be locally 、 Working on a server or in the cloud .
In order to use PyCharm Database management function , Please make sure Databse Tools and SQL The plug-in is enabled .
The main menu : PyCharm/Files -> Preference/Settings -> Plugins -> Data
PyCharm Provide Open the database tool window : The main menu View -> Tool Windows -> Database
, It can perform a series of database operations .
2. Connect to database
If you want to perform database operations , You must create data source Connect . Below to connect MySQL To introduce how to connect to the database . Other types of database connections are basically similar , For more details please Reference resources .
step1: In the database tool window View -> Tool Windows -> Database
, single click "Data Source Properties" Icon .
step2: stay "Data Sources and Drivers “ In the dialog box , single click ”+" Icon and select MySQL. Then input the corresponding information according to the prompts in the following figure . If not downloaded in advance Selected database JDBC Driver, Click on the bottom of the window Download missing driver files Link to download directly .
Tips: Of each type of database JDBC Driver You can install several different versions of , in addition to , As shown above : The system will also automatically prompt for updates . If you want to change the version used , In the current window Drivers Select the database type to change under .
step3: After the test is successful , Click on ok, New data sources MySql Create success . see Database And Service Tool window .
3. perform SQL sentence
After a successful database connection , You can query the data in the database ,PyCharm Provides a variety of query methods .
3.1 Query Console
When creating a data source , The query console will be automatically created , Can be in Services Click directly on the toolbar Console open . It can also be in Database Tool window , Right click the data source , choice open a query console, Or press F4.
Type or paste the statement to execute in console, And then execute :
Execute the above statements respectively , The results are as follows :
3.2 Execute... From the open file SQL sentence
step1: First of all, make sure that you have set up SQL Dialects, It tells the system what type of database rules are used to read and execute statements . Because we are connected to MySQL data source , So choose MySQL.
The main menu : PyCharm/File -> Preferences/Settings -> Languages & Frameworks -> SQL Dialect
:
step2: Prepare one in advance “.sql” file , Or create a new one ".sql" file , The file contains multiple statements . And then run this file .
step3: The following window will pop up , Add target data source :
step4: Click the button above Run, The toolbar Run Will be displayed :
step5: If you want to see the results of each statement , Enter... In the edit area ⌘( Ctrl + Enter) perform , You need to select the to execute the statement first Session. You can use what already exists , You can also create a new .
Tips: The data source connection is the physical communication channel .Session It is a state of information exchange . A single connection can have multiple Sessions. When using the client to connect to the database server , Both parties will establish a Session To exchange information .
Step6: Select Create a new Session after , The execute statement toolbar appears . Behind and in Query Console Execution statements are consistent .
3.3 Run the file directly from the hard disk
stay Database Click data source in the toolbar , Then choose... From the context menu Run SQL Scripts....
:
stay " Choose the path " Window , Navigate to the... To apply SQL file . The following is related to the implementation of .sql The documents are the same .
4. View results and edit data
Yes SQL sentence , The corresponding display results will be displayed in Services The toolbar , You can limit the number of bars displayed through the buttons on the toolbar , View the definition of the table and so on .
You can edit the data directly in the query results , You can also add or delete records , And submit directly to the database .
When updating records , choice Auto Pattern , Click on Submit, The update takes effect directly ,Commit And Rollback The button is always unavailable . If you choose Manual Mode submission , When there are updates ,Submit And Commit Will change from gray unavailable to available , If you click directly Commit, The update takes effect directly ; At this point, if you select Submit, Rollback The button changes from gray to available , You can click it to discard the update , Of course, you can continue to choose Commit, Make the update effective .
5. Import and export data
5.1 Derived data
1. Can be in Database Toolbar selection table 、 Views are exported directly to a file . In the figure below, select tables, Context menu selection Dump Data to Files
, Of course, you can also select a single table to export .
stay Dump Data Select the format to save the data in the window , And save the path .
2. Select from the result set to export data to a file or a clipboard . The previous result sets are displayed in Table Format display , It can be displayed in different formats through the setting of the data extractor , The same format can also be applied to export . Export data by clicking dump data Button , You can export the selected data .
In the open Dump Data window , Set the save format and path , Then choose whether to save to a file or to cut and paste the board .
5.2 Import data
Can be in Database Toolbar select data source , Context menu selection Run SQL Scripts...
.
stay " Choose the path " Window , Navigate to the... To apply SQL file . then Open.
3. It can also be in Database Toolbar select a table , Then select... From the context menu Import Data from File
After selecting, navigate to the... You want to apply SQL file , Then open the , The following import file window appears , Specify data item settings , Click on OK.
6. Summary
This section focuses on Database Tools and SQL, Its function is very powerful , We only cover some of the most commonly used functions , This is only a small part of the function , Interested students can check The related documents Continue to learn .
If there are many and complex operations on the database , The author suggests using DataGrid perhaps Navicat These specialized database tools , stay PyCharm in , We can just Database Tools As a quick debugging database related code , An auxiliary tool for real-time viewing of running results .
边栏推荐
- Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok
- Paging query, using jdbc-- paging query
- Unity is associated with vs. there is a compiler problem when opening
- Approaching history, introduction to the London Guard Museum
- 【Paper】2019_ Distributed Cooperative Control of a High-speed Train
- Unity packaging failure solution
- Geotrustov wildcard
- 0 foundation starts self-study unit notes control direction becomes larger
- One interview question and one joint index every day
- Brew install NVM command not found solution
猜你喜欢
Sailing experience not to be missed in New York Tourism: take you to enjoy the magnificent city scenery from different perspectives
Unreal 4 learning notes - data storage using blueprints
【Paper】2021_ Observer-Based Controllers for Incrementally Quadratic Nonlinear Systems With Disturbanc
[fpga] implementation of IIC read / write EEPROM
Efficiency test of adding and querying ArrayList and LinkedList
Preorder traversal of Li Kou 589:n fork tree
一条命令运行rancher
【Paper】2019_ Consensus Control of Multiple AUVs Recovery System Under Switching Topologies and Time D
Easyrecovery data recovery software recovers my photo and video data two years ago
力扣209. 长度最小的子数组
随机推荐
【Paper】2019_ Consensus Control of Multiple AUVs Recovery System Under Switching Topologies and Time D
Unity is associated with vs. there is a compiler problem when opening
Solution to the 292 week match of Li Kou
[control] multi agent system summary. 5. system consolidation.
[UAV] gyroscope data analysis, taking Victor intelligent jy901b as an example
Why does the computer have no network after win10 is turned on?
Lambda&Stream
【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
Unity script life cycle and execution sequence
Yolov5 torch installation
Check London attractions suitable for parents and children in winter vacation
Webots learning notes
Unreal 4 unavigationsystemv1 compilation error
JS 数组的排序 sort方法详解
Static keyword
力扣589:N 叉树的前序遍历
Unreal 4 learning notes - data storage using blueprints
【Paper】2020_ Research on defense and evaluation strategy of heterogeneous UAV formation_ Zuojiankai
Unity lens making
Wildcard SSL certificate issuing time