MajidRamzi
MajidRamzi

Reputation: 438

Connect to MySQL Data Source in PHPStorm

I'm using an IDE "Phpstorm" with "wampserver". i want to connect with MySQL data source, but i'm getting a problem:

Connection to MySQL - DatabaseName@localhost failed: Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.persistence.database.console.RemoteJdbcServer.main(RemoteJdbcServer.java:15)

I also downloaded mysql-connector-java-gpl-5.1.29.msi and installed it, but I'm still getting some problems.

Upvotes: 25

Views: 19874

Answers (7)

oriadam
oriadam

Reputation: 8539

PHPStorm 2020.1 with Material Dark theme:

  1. Hit Alt+0 or View→Tool Windows→Database to open the Database tool window.
  2. Click the pancakes-with-wrench icon
  3. Click the TEST CONNECTION button
  4. This will prompt you to download the drivers - do it
  5. You will have to enter your root password again

enter image description here

Upvotes: 1

Jerry
Jerry

Reputation: 666

Short version:

  • Open the Database tab, usually located on the very upper right of PHPSTORM.
  • Click on the small wrench (Data Source and Property)
  • In this new popup window choose MySQL from the left.
  • Delete Red driver files with the minus symbol
  • Click Download

From there on you should be good to go. (phpstorm handles the rest)

Detailed version:

  • Open the Database tab, usually located on the very upper right of PHPSTORM.
  • Click on the small wrench (Data Source and Property)

enter image description here New Version v2020: New Version 2020.1 If it's not there open it from View -> Tool Windows -> Database

view New Version v2020 New Version 2020.1 - In this new popup window choose MySQL from the left.

Should look like this New Version v2020: New Version (V 2020.1) - Now you should be on the settings tab where you can see driver files, if any of them are red just delete them with the minus symbol, as soon as there are no driver files left you are able to click on download.

If any of the above fail try these:

  • Delete the drivers in use and reinstall. Usually located at ~/.PhpStormXXXX/config/jdbc-drivers. After that repeat the first instructions in this post. (short version)

  • Using a proxy? Make sure you have configured it within phpstorm! At Appearance & Behavior -> System Settings -> HTTP Proxy.

  • Make sure you have the latest drivers: Create a new mysql datasource, if the driver needs an update it will display it on the very bottom of the popup

  • try other versions enter image description here New Version v2020: New Version 2020.1

Installing the Driver Manually

I couldn't find any official Jetbrains mysql driver repo page, but these urls are official and work:

The Newest version number can be found here: https://dev.mysql.com/downloads/connector/j/5.1.html

just replace the [VERSION] with the current version e.g. http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-[VERSION]-bin.jar

Add the downloaded file with clicking on the small grey plus. (in older versions green and on the right)

adding files New Version v2020: New Version (2020.1)

Or try the official mysql repo (caution you MUST register to download!):

Go to http://dev.mysql.com/downloads/connector/ within the dropdown select "Platform Independent" it will show you the options to download tar or zip files. Download one of them and extract it, Within the resulting folder you will find a mysql-connector-XXX.jar file. Add it to phpstorm in the mysql datasource dialog box.

Other stuff:

Upvotes: 29

michondr
michondr

Reputation: 191

if nothig of above works, you can delete .PhpStorm2017.3/config/jdbc-drivers folder. then navigate to your db properties and download the driver again

Upvotes: 0

ryanyuyu
ryanyuyu

Reputation: 6486

Code Monkey's answer pointed me in the right direction, but my firewall blocked the download from within PHPstorm. Luckily the error message included the download URL to find the driver.

Driver download failure

So I downloaded the driver with help from the URL, and then added it manually:

Manually add driver .jar

Upvotes: 2

James Shisiah
James Shisiah

Reputation: 383

Anyone else who came here trying to locate the Database tab in the latest version of PhpStorm (Version 2017.1), which is hidden at first, try the following, taken from PhpStorm Website

Database support is provided through the Database Tool Window on the right-hand side of the IDE. Use the View | Tool Windows | Database menu or Find Action, by pressing Ctrl+Alt+A (Alt-CMD-A on Mac OS X) and search for "Database" to open it.

Upvotes: 0

Eda
Eda

Reputation: 418

Had the same issue. I resolved it in the Data source and drivers window on panel Mysql. There is checkbox "Use provided driver" and next to it there was link "Version 5.1 (latest)". I clicked on it a now it works.

Upvotes: 0

CodeMonkey
CodeMonkey

Reputation: 3331

When I had this issue, there was a section of the Data Sources and Drivers Dialogue box that said "Driver Files" I expanded it and there was a link to download driver files.

I clicked it - and after a few seconds (with no obvious visual progress indicator) the message changed to say using MySQL drivers.

After that it worked.

Upvotes: 58

Related Questions