Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to MySQL Data Source in PHPStorm

Tags:

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.

like image 678
MajidRamzi Avatar asked Feb 09 '14 08:02

MajidRamzi


Video Answer


2 Answers

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.

like image 155
CodeMonkey Avatar answered Sep 19 '22 03:09

CodeMonkey


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:

  • http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-5.1.35-bin.jar http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-5.1.40-bin.jar http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-5.1.44-bin.jar http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-5.1.45-bin.jar http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-5.1.46-bin.jar http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-5.1.47-bin.jar http://download.jetbrains.com/idea/jdbc-drivers/mysql-connector-java-5.1.48-bin.jar

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:

  • Useful phpstorm UI reference link
like image 31
DevJ3rry Avatar answered Sep 20 '22 03:09

DevJ3rry