Master DataGrip: Connect MySQL & PostgreSQL Quickly with Step‑by‑Step Guide
This tutorial walks you through preparing your environment, configuring DataGrip, and executing SQL scripts to connect and manage both MySQL and PostgreSQL databases, complete with hardware requirements, connection parameters, sample code, troubleshooting tips, and performance optimization advice.
1. Pain point: Why are you still using Navicat?
Late at night you encounter SQL errors and hesitate to open Navicat; DataGrip offers a unified tool that manages MySQL, PostgreSQL, Oracle and more, acting as a "universal database manager".
2. Environment preparation
Hardware requirements : at least 8 GB RAM (16 GB recommended), SSD storage.
Software environment :
Operating System: Windows 10/11, macOS, Linux.
Database versions: MySQL 8.0.42, PostgreSQL 9.6.
Java: JDK 11+ (for JDBC testing).
Download the latest DataGrip installer from the JetBrains website.
3. Complete process for connecting MySQL
1. Database configuration preparation
Ensure the MySQL service is running and verify with the command line:
mysql -u root -pAfter entering the password, list databases:
SHOW DATABASES;Confirm you can access the server.
2. DataGrip connection configuration
Open DataGrip, click Database → New Data Source .
Select MySQL and fill in the parameters:
Host: 127.0.0.1
Port: 3306
Database: testdb
User: root
Password: 123456
SSL: Disable
Save Password: Yes
Click Test Connection ; when successful, click Finish .
3. Execute SQL example
Run the following script in the SQL editor:
-- Create test table
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);
-- Insert test data
INSERT INTO users (id, name, email) VALUES
(1, '张三', '[email protected]'),
(2, '李四', '[email protected]');
-- Query data
SELECT * FROM users;Result:
+----+----------+-----------------------+
| id | name | email |
+----+----------+-----------------------+
| 1 | 张三 | [email protected] |
| 2 | 李四 | [email protected] |
+----+----------+-----------------------+4. Complete process for connecting PostgreSQL
1. Database configuration preparation
Ensure PostgreSQL is running and verify with:
psql -U postgresList tables:
\dt2. DataGrip connection configuration
Open DataGrip, click Database → New Data Source .
Select PostgreSQL and fill in the parameters:
Host: 127.0.0.1
Port: 5432
Database: testdb
User: postgres
Password: 123456
SSL: Disable
Save Password: Yes
Test the connection and finish.
3. Execute SQL example
-- Create test table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);
-- Insert test data
INSERT INTO users (name, email) VALUES
('王五', '[email protected]'),
('赵六', '[email protected]');
-- Query data
SELECT * FROM users;Result:
id | name | email
----+------+-------------------
1 | 王五 | [email protected]
2 | 赵六 | [email protected]5. Component relationship and execution environment
DataGrip : database management tool, runs as an IDE plugin.
MySQL/PostgreSQL : database services, run on local or remote servers.
SQL editor : where you write and execute SQL, located at the bottom of DataGrip.
Result window : displays query results on the right side of DataGrip.
Database navigation tree : shows database structure on the left side.
6. Common issues and solutions
Connection failures : check firewall ports (3306/5432), verify service status, ensure correct password case.
SQL execution errors : verify syntax (semicolon for MySQL, \g for PostgreSQL), ensure proper privileges, check DataGrip logs (Help → Show Log).
Performance problems : optimize queries with EXPLAIN, increase max_connections for MySQL, use indexes.
7. Advanced tip: Multi‑database comparison
Key differences between MySQL and PostgreSQL:
Primary key: AUTO_INCREMENT (MySQL) vs SERIAL (PostgreSQL).
Transactions: supported by both.
JSON type: supported by both.
Timezone handling: supported by both.
Syntax case sensitivity: MySQL is case‑sensitive, PostgreSQL is not.
8. Conclusion
You now have the core skills to connect MySQL and PostgreSQL with DataGrip. Mastery is not just about writing SQL but using DataGrip to quickly locate issues, which can save at least 30 % of your time.
IT Xianyu
We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.