Idea作為一款常用的Java開發工具,對于連接數據庫也提供了很好的支持。本文將介紹如何使用Idea連接MySQL數據庫。
首先,在Idea中打開項目,依次點擊菜單欄中的“View”、“Tool Windows”、“Database”,如下圖所示:
----------------| | File Edit | | | | View | | | | Help | |----------------| | Run Debug | | --------------- | | Database | | ---------------
接下來,在Database面板中,點擊左上角的“+”號,選擇“Data Source”為MySQL,如下圖所示:
----------------| | File Edit | | | | View | | | | Help | |----------------| | Run Debug | | --------------- | | Database | | --------------- | | +
之后,填寫連接MySQL數據庫的信息,包括Host、Port、Database、User和Password等,如下:
----------------| | File Edit | | | | View | | | | Help | |----------------| | Run Debug | | --------------- | | Database | | --------------- | | + | | MySQL | | Host | | Port | | Database | | User | | Password
填寫完畢后,點擊“Test Connection”進行連接測試,如下:
----------------| | File Edit | | | | View | | | | Help | |----------------| | Run Debug | | --------------- | | Database | | --------------- | | + | | MySQL | | Host | | Port | | Database | | User | | Password | | Test Connection
如果連接成功,則提示“Connection successful”,如下:
----------------| | File Edit | | | | View | | | | Help | |----------------| | Run Debug | | --------------- | | Database | | --------------- | | + | | MySQL | | Host | | Port | | Database | | User | | Password | | Connection successful
最后,點擊OK保存配置信息,連接MySQL數據庫即可。