How to connect IntelliJ with local MySQL? - mysql

I have been struggling to learn how the localhost MySQL and IntelliJ to connect and program a database related task. Is that Possible? If yes, how to achieve it?

Connecting to a local instance is essentially the same as connecting to a remote instance of MySQL. Just substitute either localhost, or 127.0.0.1 in place of the IP address you would use normally.
To add a new database connection (called a data source in IntelliJ), open the Database window View -> Tool Windows -> Databases, then click the + sign and select Data Source and then MySQL from the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.
To open a connection, right click on your new data source and select Open Console.
Official IntelliJ Documentation - Managing Data Sources

As of Community version 2017.2, the DB Browser does not come bundled with the IDE (at least not on my last two installations). In order to activate it, you should navigate in the IDE in **File->Settings->Plugins->Browse repositories and select "Database" from the dropdown menu. From there you can install the Database Navigator. After the installation has been successful, you should restart the IDE. Then you can select **View->Tool windows->DB Browser.

In recent versions of Idea Community (about 2017.3, but I am not sure) there is no Database tool available anymore, only in Idea Ultimate [1]. Yet worse, the plugin Database Navigator that would fit here to solve this problem is not compatible anymore, at least not with 2018.3 [2].
Uninstalling Idea right now, unfortunately.
[1] https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000411990-Database-option-not-available-under-View-Tool-Windows-in-Intellij-v2018-1-Community-Edition-
[2] https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001759260-Dan-Cioacas-Database-Navigator-plugin-v3-0-8222-0-is-incompatible-with-latest-IntelliJ-IDEA-2018-3

To add a new database connection (called a data source in IntelliJ), open the Database window View -> Tool Windows -> Databases, then click the + sign and select Data Source and then MySQL from the sub-menu. The defaults for the MySQL connection should for a local install of MySQL.
To open a connection, right click on your new data source and select Open Console.
to download Drivers click on "Download missing Drivers" in bottom of the window.
if you want to add JDBC and connect other database vendor like workbench projects (instead of using intelliJ Consol) just follow the steps bellow :
Using JDBC drivers #
Create a connection to a database with a JDBC driver #
If you cannot find a name of a database vendor in the list of data sources, download a JDBC driver for the database management system (DBMS), and create a connection in IntelliJ IDEA. With the JDBC driver, you can connect to DBMS and start working.
In the Database tool window (View | Tool Windows | Database), click the Data Source Properties icon.
In the Data Sources and Drivers dialog, click the Add icon (+) and select Driver and Data Source.
Click the User Driver link.
In the Driver files pane, click the Add icon and select Custom JARs.
Navigate to the JAR file of the JDBC driver, select it, and click
OK.
In the Class field, specify the value that you want to use for the
driver.
Click Apply.
Return to the created data source connection.
Specify database connection details. Alternatively, paste the JDBC URL in the URL field.
To set an empty password, right-click the Password field and select Set empty.
To ensure that the connection to the data source is successful,
click Test Connection.
For more information read the official answer of Jetbrains in following link :
Configuring database connections
https://www.jetbrains.com/help/idea/configuring-database-connections.html#Configuring_database_connections.xml

For anyone who is having trouble connecting IntelliJ Community Edition with MySQL in 2021.
(In IntelliJ Ultimate Database connectivity is supported by default and you can follow the steps shown in the previous answers. However IntelliJ Community Edition does not support it by Default).
Here is what you have to do:
Install "Database Navigator" Plugin. (Settings->Plugins->Marketplace->Search Database
Navigator and install)
Open DB Browser Tab (next to the button that opens/closes Project Window) -> Click Options logo
-> '+' -> Fill the Database fields (Name, host, Port, DB Name, User and Password).
Download the MySQL Java Connector
by searching google for 'java connector mysql'.
Go to File->
Project Structure -> Modules-> Dependencies. Click the '+' on the right side and select 'JARs or directories'.
Navigate and find the Java connector you just downloaded (the file
looks like this: mysql-connector-java-8.0.26.jar). Click apply
and in the project window, under External Libraries, you will see
the .jar file.

For WebStorm you need plugin "database-navigator"
https://plugins.jetbrains.com/plugin/1800-database-navigator

Related

MySQL Installation Error when Initializing database [duplicate]

I was installing MySQL installer on my windows 8 machine. During the server configuration process, it gets stuck at "starting server" and doesn't move any further. The log for the same is :
Beginning configuration step: Stopping Server [if necessary]
Ended configuration step: Stopping Server [if necessary]
Beginning configuration step: Writing configuration file
Ended configuration step: Writing configuration file
Beginning configuration step: Updating firewall
Adding firewall rule for MYSQL56 on port 3306.
Successfully added firewall rule.
Ended configuration step: Updating firewall
Beginning configuration step: Adjusting Windows service [if necessary]
Attempting to grant Network Service require filesystem permissions.
Granted permissions.
Adding a new service
New service added
Ended configuration step: Adjusting Windows service [if necessary]
I have already tried the following:-
* Un-installed all the programs that were in any way related to MySQL.
* Deleted the MySQL folder from C:\Program Files.
* Cleared my registry.
and then re-installed the program, but all in vain.
The link MySQL Installer Stuck on "Starting Service" also shows the same problem but the solution provided is not working for me.
Here is what I did:
Installed it with mysql-installer-web-community-5.6.23.0.msi
For my purposes I selected "Custom" install with MySQL servers 5.6.22 - X64 and MySQL Connectors -> Connector ODBC/5.3.4 - 64
Next -> Execute -(ready to configure) -> Next
Config type: Development machine, all defaults (TCP/IP, Port: 3306, Open firewall)
Typed in MySQL Root Password
MySQL user Accounts -> Add user (username, password, OK) -> Next
Configure MySQL Server as a Windows Service (CHECKED)
Windows Service Name: MySQL56 (default)
Start the MySQL Serve at System Startup
THIS IS CRUCIAL (BUG IS HERE): Run Service as...
Standard System Account (CHECKED - but it will be disregarded and that is BUG)
Next -> Execute, Installation hangs on Starting server, so wait for a while to time out (or don't, your choice). When Dialog (might be covered with other windows) popup with message "Configuration of MySQL Server is taking longer than expected..., here click OK (so to wait longer)
Meanwhile go to Start -> Control Panel -> Administrative Tools -> Services -> find MySQL56, right click on it -> Properties -> select Log On Tab AND HERE IS BUG -> Although Local System Account was selected, Somehow "This account: Network Service (with some password) was selected -> Select Log on as: Local System Account, Allow service to interact with desktop -> Apply -> Go back on general tab
On general tab click on "Start" button to start service and here it is! Service is started! Click on OK to close MySQL56 Properties dialog. Close Services dialog. Close Administrative tools. Close control panel.
And by that time (while you were closing those dialogs) when you look at MySQl Installer Dialog all steps are finished and checked: Starting Server, Applying security... Creating user accounts.. Updating Start menu link
Confirm with Finish -> Next -> Finish
That's it, happy MySQL-ing :)
The installer has another issue that I discovered today.
I had the same issue of the installer hanging on "Starting Server". However, after looking at the windows Event Viewer under Windows Logs -> Application, I discovered the error
"Too many arguments (first extra is 'Something').For more information, see Help and Support Center at http://www.mysql.com.".
The issue is that the installer cannot handle spaces in the windows service name (the name I used was Something MySQL). Simply change the name to one without spaces.
My issue was the special character in the password.
What I did to resolve being stuck at the Attempting to Start Server:
1. Use the installer to uninstall the previous version/installation
2. Validate and delete the existing MySQL Folders (DATA and App)
3. Re-install using the installer
4. Use a strong lengthy password with no special character password
This seems to be a chronic issue with MySQL Installer even now (v1.4.17.0). No matter what, every time I (re-)configure an instance on Windows 7 Pro or Server (2008 R2) it hangs at this point.
Simplest fix is:
When the installer hangs, open Windows Services and locate your mySQL service instance(s).
Double-click to open the/an instance and set Log on as: to Local System account and check Allow service to interact with desktop.
Optionally but preferably set the Recovery options to allow the service to resume after a problem.
Ensure that Startup type is set to Automatic (or whatever your preference is).
Click Apply and then click Start (or click OK and then start the service).
Return to the MySQL Installer and close any open warning about waiting for the process to complete and the process should continue.
Repeat as required for each MySQL Server instance.
Note: The installer seems to not enable the firewall exception that you may have selected when MySQL Server was first configured, so you may have to reconfigure again to open the firewall.
Side note: All-in-all, I'd have to say that after only two days of using the MySQL ecosystem, I'm less than impressed by how buggy things are. I would estimate that I had to set up two server interfaces about 6 times before everything worked as advertised. Workbench crashed on me 5+ times in the first day alone and I've had to traipse through any number of forums finding answers to stuff like this. Be prepared to do the same.
I had the same problem where it changed from Local System Account to Network Service, I changed it in the services back to Local System Account. This however did not work. I came across another forum that suggested having spaces in the services name was causing the problem so I took out the spaces and put underscores and sure enough it worked!
Change spaces to underscores!
Adding this for others.
I had install set up to configure windows service.
Looking in Windows Event Viewer => Windows Logs => Application I found:
C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe: Error while setting value '0.0' to 'lower_case_table_names'
Checking the init file in C:\ProgramData\MySQL\MySQL Server 5.6\my.ini
I found:
# Specifies the on how table names are stored in the metadata.
# If set to 0, will throw an error on case-insensitive operative systems
# If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive.
# If set to 2, table names are stored as given but compared in lowercase.
# This option also applies to database names and table aliases.
lower_case_table_names=0.0
I changed the value to 0, but on reinstall it reappeared as 0.0 so during the install and whilst the installation hanged at 'Starting Server' I edited the my.ini file, saved it, opened the services viewer and manually started the service MySql56. The installation then completed
The MySQL developers insist that running the MySQL service Logged On as NETWORK SERVICE IS the proper way to do it and that running it as LOCAL SYSTEM opens security holes. Okay, people, the root of the problem here is that NETWORK SERVICE can't access the locations where the log files are configured to be. I suspect this error occurs when a folder is specified (by clicking Browse) that the NETWORK SERVICE doesn't have access to. In my case, I specified the log files to be written under My Documents in a folder called MySQL Logs. So, (and this can be done while the installer dialog is open, it says the installer is taking a long time, and prompting you to Wait or Cancel,):
I simply granted full control of that folder to the NETWORK SERVICE by right-clicking on the folder, selecting Properties, selecting Security, then clicking Add, then typing in "NETWORK SERVICE". Then I selected NETWORK SERVICE and clicked the checkboxes Allow for Full control and Modify.
I've figured this one out. Mine was getting stuck at "Starting Server" too and Event Viewer had this -
The description for Event ID 100 from source MySQL cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
innobase_buffer_pool_size can't be over 4GB on 32-bit systems
So I figured out the problem was trying to start the 32-bit version of MySQL that comes bundled in with the installer on a 64-bit machine could have been the problem. Although, MySQL states it will install 64-bit of the database.
What I did was downloaded a 64-bit zipped version and unpackaged it into a temporary location. I re-ran the installer and let it install mysql. I replaced the contents of that with the other version from the temporary location without stopping the installer. Then I continued with configuration steps of the installer. It managed to start the service.
Here's full trace of the log.
Beginning configuration step: Stopping Server [if necessary]
Ended configuration step: Stopping Server [if necessary]
Beginning configuration step: Writing configuration file
Ended configuration step: Writing configuration file
Beginning configuration step: Updating firewall
Adding firewall rule for MySQL56 on port 3306.
Successfully added firewall rule.
Ended configuration step: Updating firewall
Beginning configuration step: Adjusting Windows service [if necessary]
Attempting to grant Network Service require filesystem permissions.
Granted permissions.
Adding new service
New service added
Ended configuration step: Adjusting Windows service [if necessary]
Beginning configuration step: Starting Server
Starting MySQL as a service
Ended configuration step: Starting Server
Beginning configuration step: Applying security settings
Attempting to update security settings.
Updated security settings.
Ended configuration step: Applying security settings
Beginning configuration step: Creating user accounts
Attempting to Add New MySQL Users
Added New Users.
Ended configuration step: Creating user accounts
Beginning configuration step: Updating Start Menu Link
Attempting to verify command-line client shortcut.
Verified command-line client shortcut.
Verified command-line client shortcut.
Ended configuration step: Updating Start Menu Link
I found another solution: I was using a complex password with special characters in it. When I switch to using only alphanumeric characters in the password, it installed with no issues.
I faced the same problem. Completely removing MySql from my PC and then installing it from scratch fixed my problem.
How to remove MySql Completely:
Run Command Prompt as Administrator and execute the following command to stop and
remove MySQL service.
Net stop MySQL
Sc delete MySQL
Go to Control Panel >> Programs >> Programs and Features, select MySQL Server 5.x and
click Uninstall. (If you can uninstall MySQL from Control Panel)
Open Windows Explorer and go to Organize > Folder and search options, Select the “View”
tab and under “Hidden files and Folders” choose “Show hidden files and folders”. Now
explore the following locations and delete following folders.
C:\Program Files\MySQL
C:\Program Files (x86)\MySQL
C:\ProgramData\MySQL
And if this exists, delete it too:
C:\Users\[User-Name]\AppData\Roaming\MySQL
Restart your PC and reinstall MySQL. That’s all!
I made this problem disappear by upgrading from 5.7 to 8.0.
Specifically I:
Uninstalled MySQL 5.7 (through the "MySQL Notifier").
Downloaded and ran mysql-installer-web-community-8.0.14.0.msi from https://dev.mysql.com/downloads/windows/installer/8.0.html
None of the above solutions worked for me. I finally installed an older version. You can look at the version release history from here. Instead of installing the latest MySQL version 8.0.21.0, I instead installed version 8.0.18.0 from here. It finally worked.
I managed to solve this issue by selecting "Do not secure Data folder" option (a third one in the list) during installation. Explained here: https://dev.mysql.com/doc/mysql-installer/en/server-file-permission-options.html
. Seems like installer could not get access to it

DBeaver error resolving maven dependencies

I am trying to connect to a remote MySQL database using DBeaver 3.6.3.
But when I try to add the server as a new connection, I need to select a connection type. I select MySQL and as soon as I click on next, it gives me this error
I have tried restoring driver settings to default - no effect.
I have tried removing the metadata folder in Users and restarting - no effect
In my case I had to add the Maven index site url in DBeaver as follows:
Go to DbBeaver "Preferences" menu
Locate "Connections" -> "Drivers" -> "Maven"
Click "Add" and paste this link: https://mvnrepository.com
Click "Apply" and "Close"
On the driver settings menu that will appear, click "Download"
After the download has finished, I was able to connect to the database.
Have you tried to reinstall the driver?
I've tried DBeaver on Linux, mysql connector v 5.1.39 worked fine (mysql 5.6.15).
I had issues a month ago with dbeaver and connecting to a mssql db, updating dbeaver to the v4.0.0 fixed it, maybe you could try that too?
You'll have to build it though, if this doesn't scare you: https://github.com/serge-rider/dbeaver
It is possible that you don't have direct internet access on your working plan (e.g. because of some corporate proxy).
In this case you could try:
Download drivers manually from https://jdbc.postgresql.org/download.html and then add jars in driver editor
Try to configure HTTP proxy in preferences
Note: Ref site
https://github.com/dbeaver/dbeaver/issues/1898
I fixed maven dependencies error encountered while installing db driver as follow:
first set up http_proxy if needed
then add the mvn URL repository in the download configuration settings as describe in this issue
Solution tested on DBeaver Version 21.3.5
if any body is facing the above issue then remove the jar files from dbvear library and add the below jar file download from the link below and add it in the driver library and try to connect it.it worked for me hope this might helpful
https://jar-download.com/artifacts/com.microsoft.sqlserver/mssql-jdbc/8.2.0.jre8/source-code

How to set datasource for MySQL database in Microsoft SQL Report Builder 3.0?

I am using Microsoft SQL Server Report Builder 3.0. And I have remote Linux Server(with certain IP) that have MySQL database. I want connect this MySQL database from Report Builder (in my PC), So that I can create some reports about it. How can i do that? Please help and Thanks.
First, you need to download and install (32-bit or 64-bit) appropriate MySQL connector.
MySQL ODBC connector
After installation, you need to create ODBC Data Source Name (DSN) on this way:
Open Control Panel -> Administrative Tools -> ODBC Data Sources (32-bit or 64-bit, depending of installed connector)
Choose System DSN tab and click on Add
In dialog window, choose installed connector for MySQL
In new dialog window populate Data source name field with descriptive name, fill MySQL server address and port (IP address or server network name) and fill credentials that have enough permissions to MySQL server. Catalog field is optional field. Test the connection.
Open Microsoft Report Builder 3.0, and create new report. While creating dataset, you need to choose data source. Click New Data Source (or just New) and in the dialog window for Connection type, choose ODBC and in the Connection string choose Build option.
In new dialog window, in Data source specification section choose your DSN that you created in stages 2, 3 and 4 and test connection.
Voila :)

How to Connect MySql from Eclipse using Data Source Explorer

I need help. Could you please answer these question? I would like to connect eclipse to my database and I have tried these in eclipse: Window>Show View>Other>Data Source Explorer. After that we get Database Connections under the eclipse and then right click on the database connection and click on New... then select MySql under Connection Profile Types: and I click on New Driver Definition. Under New Driver Definition dialog, there exists MySql JDBC Driver with specific System Version. I choose one, but the OK button is disabled. Also at the top it says: "Unable to locate JAR/zip in file system as specified by the driver definition: mysql-connector-java-xxx-bin.jar".
How can I specify a Driver Template and Definition Name under New Driver Definition dialog of Data Source Explorer (in Data Tools Platform)
I dont know your Eclipse version or your MySql server version but for Kepler and mysql 5.5 server, here what I did. First I downloaded mysql connector java jar file(mysql-connector-java-5.1.36-bin.jar) from http://dev.mysql.com/downloads. Then On the New Driver Definition dialog page, I choose MySQL JDBC Driver|MySQL|5.1 under Name/Type tag. Go to JAR List tab Clear all and Add JAR/Zip... and choosed my already downloaded jar file. Finally at the Properties tab I filled them like this:
Connection URL: jdbc:mysql://localhost:3306
Database Name: MyDatabaseNameHere
Driver Class: com.mysql.jdbc.Driver
Password: MyPasswordHere
User ID: root
In the end, OK butten changed to enabled and that is all.
I also faced same issue. Just download the specific mysql JAR file needed. Now you need to add it to the JAR files tab. But before doing it click on clear all. That is the important step.

JDeveloper MySQL error Driver not found

I am running MySQL db using the latest wamp server. Using Oracle JDeveloper 11g. I have placed the MySQL connector jar in .../jdeveloper/jdev/lib folder and added the jar as a library in my adf application .
. I am able to create a connection to the db, view the tables in DB Navigator of JDev, also create Entity and View Objects. However when I try to run the Application Module, I get an error popup saying could not create connection, driver not found. I have the ApplicationModule data source configuration set to JDBC Datasource.
Help!!!
. Thank you
Update :
The Error Log-----------------------------
[232] Using the oracle.jbo.server.ConnectionPoolDataSource to acquire a connection...
[233] Creating a new pool resource
[234] Trying connection/3: url='jdbc:mysql:/*****' user='root' password='*****' ...
[235] DBTransactionImpl.initTransaction: Login failed
[236] java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/myDatabase
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at oracle.jbo.server.URLConnectionHelper.getConnection(URLConnectionHelper.java:187)
at oracle.jbo.server.URLConnectionHelper.getConnectionFromDriver(URLConnectionHelper.java:50)
at oracle.jbo.server.ConnectionPool.createConnection(ConnectionPool.java:195)
at oracle.jbo.server.ConnectionPool.instantiateResource(ConnectionPool.java:166)
at oracle.jbo.pool.ResourcePool.createResource(ResourcePool.java:580)
at oracle.jbo.pool.ResourcePool.useResource(ResourcePool.java:313)
at oracle.jbo.server.ConnectionPool.getConnectionInternal(ConnectionPool.java:102)
The username and password used to connect to my database is correct, I am able to test it in the connection manager.
I am getting this error on run of Application Module, so I dont think the Integrated Weblogic Server is an issue here.
I have made sure that in libraries the mysql-connector jar is marked as "Deploy by default".
The jdbc jar file should also be placed where the embedded WebLogic can find it. So locate your defaultDomain directory under the JDeveloper's system directory /users/youruser/roaming/app data/JDeveloper
And locate the lib directory there.
Or make sure that the library you created in JDeveloper for the JDBC jar is marked as "Deploy by default".
put the mysql-connector**.jar in ~/.jdeveloper/xxxxxxx/DefaultDomain/lib
Configure JDeveloper to work with MySQL Connector/J
1-Download MySQL Connector/J 3.0.11 and copy the JDBC driver JAR file to a known location, such as /jdev/lib
From the Tools menu, select Default Project Properties.
In the tree view, select Libraries.
In the right pane, select New. The Create Library dialog will be displayed.
Name the library MySQL JDBC.
Set the location to Users Libraries.
Click Edit for the Class Path. The Edit Class Path dialog is displayed.
Click Add Entry. The Select Path Entry dialog is displayed.
Navigate to the JAR file for the MySQL Connect/J JDBC driver (it should be called something like mysql-connector-java--bin.jar).
Click on the jar file and click Select.
Click OK.
The library will be defined, and it will be in the Selected Libraries list.
You probably don't want that library to be defined in all your projects, so shuttle it over to the Available Libraries list.
this link help me a lot :
Oracle JDeveloper 11g with MySQL