How do you connect to a MySQL database using Oracle SQL Developer? - mysql

I have Oracle SQL Developer already installed and am able to connect to and query Oracle databases.
Using Help -> Check for Updates I was able to install the Oracle MySQL Browser extension but there are no connection options for MySQL databases.

Under Tools > Preferences > Databases there is a third party JDBC driver path that must be setup. Once the driver path is setup a separate 'MySQL' tab should appear on the New Connections dialog.
Note: This is the same jdbc connector that is available as a JAR download from the MySQL website.

In fact you should do both :
Add driver
Download driver https://maven.atlassian.com/content/groups/public/mysql/mysql-connector-java/5.1.29/
To add this driver :
In Oracle SQL Developper > Tools > Preferences... > Database > Third Party JDBC Drivers > Add Entry...
Select previously downloaded mysql connector jar file.
Add Oracle SQL developper connector
In Oracle SQL Developper > Help > Check for updates > Next
Check All > Next
Filter on "mysql"
Check All > Finish
Next time you will add a connection, MySQL new tab is available !

Here's another extremely detailed walkthrough that also shows you the entire process, including what values to put in the connection dialogue after the JDBC driver is installed: http://rpbouman.blogspot.com/2007/01/oracle-sql-developer-11-supports-mysql.html

My experience with windows client and linux/mysql server:
When sqldev is used in a windows client and mysql is installed in a linux server meaning, sqldev network access to mysql.
Assuming mysql is already up and running and the databases to be accessed are up and functional:
• Ensure the version of sqldev (32 or 64). If 64 and to avoid dealing with path access copy a valid 64 version of msvcr100.dll into directory ~\sqldeveloper\jdev\bin.
a. Open the file msvcr100.dll in notepad and search for first occurrence of “PE “
i. “PE d” it is 64.
ii. “PE L” it is 32.
b. Note: if sqldev is 64 and msvcr100.dll is 32, the application gets stuck at startup.
• For sqldev to work with mysql there is need of the JDBC jar driver. Download it from mysql site.
a. Driver name = mysql-connector-java-x.x.xx
b. Copy it into someplace related to your sqldeveloper directory.
c. Set it up in menu sqldev Tools/Preferences/Database/Third Party JDBC Driver (add entry)
• In Linux/mysql server change file /etc/mysql/mysql.conf.d/mysqld.cnf
look for
bind-address = 127.0.0.1 (this linux localhost)
and change to
bind-address = xxx.xxx.xxx.xxx (this linux server real IP or machine name if DNS is up)
• Enter to linux mysql and grant needed access for example
# mysql –u root -p
GRANT ALL ON . to root#'yourWindowsClientComputerName' IDENTIFIED BY 'mysqlPasswd';
flush privileges;
restart mysql - sudo /etc/init.d/mysql restart
• Start sqldev and create a new connection
a. user = root
b. pass = (your mysql pass)
c. Choose MySql tab
i. Hostname = the linux IP hostname
ii. Port = 3306 (default for mysql)
iii. Choose Database = (from pull down the mysql database you want to use)
iv. save and connect
That is all I had to do in my case.
Thank you,
Ale

Although #BrianHart 's answer is correct, if you are connecting from a remote host, you'll also need to allow remote hosts to connect to the MySQL/MariaDB database.
My article describes the full instructions to connect to a MySQL/MariaDB database in Oracle SQL Developer:
https://alvinbunk.wordpress.com/2017/06/29/using-oracle-sql-developer-to-connect-to-mysqlmariadb-databases/

You may find the following relevant as well:
Oracle SQL Developer connection to Microsoft SQL Server
In my case I had to place the ntlmauth.dll in the sql-developer application directory itself (i.e. sql-developer\jdk\jre\bin). Why this location over the system jre/bin I have no idea. But it worked.

Related

MACOS / MySQL / SQL Developer connection error - timezone issue

On my Mac PC, I have installed MySQL and SQL Developer as well as the MySQL Connector/J, the official JDBC driver for MySQL, so that the MySQL tab appears in the connection window of SQL Developer.
In the SQL Developer connection window, I am filling in the following details
Connection name: test
Username : root
Password: xxxxx
In the MySql tab within this connection window, the hostname and port is auto populates the values localhost and 3306.
There is a button called 'Choose Database', when I click on this button I am getting the below error message in red color
"Status : Failure - The server time zone value 'AEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specific time zone value if you want to utilize time zone support"
How do I fix this issue so that I can connect to the MySql database from SQL developer?
PS: I am currently based in Sydney, Australia.
The problem got resolved by adding the below entries in the below mentioned file. In the new mysql database installations, this file would not be present so create the file so you will have create new plain text file with root privileges. When you start the MySQL server, this file will be read every time. The value specified below is a global parameter.
/etc/my.cnf
[mysqld]
default-time-zone='+10:00'
The single quotes should typed in not copy pasted.
And then restart the MySQL server.
Upvote to Nitin Puthran's answer.
If you have a Homebrew installation of mysql, my.cnf is in the Cellar mySql directory (not etc). For my version this is:
/usr/local/Cellar/mysql#5.6/5.6.41/my.cnf
[mysqld]
default-time-zone='+10:00'
And restart the mySql server.
I installed MySQL 8 with native packages on Mojave (10.14.6). As far as I can tell, there is no such thing as a my.cnf file. I couldn't get MySQL to recognize any my.cnf file, even by specifying one on the configuration tab of the MySQL settings applet in System Preferences. The only thing that worked for me was editing /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist and adding <string>--default-time-zone=America/Denver</string> to the Program Arguments section. Either restart your Mac or use the aforementioned applet to restart the server.
I imagine using a city name will only work if you have loaded timezone data into MySQL. mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql worked for me. Otherwise an offset like the above answers should work.

Fresh Lucee 5.2.7.63 install unable to connect to fresh MySQL 8 install

I recently setup a new AWS server to be used as a web server for some small utility apps. It's running Windows 2012. I then:
Installed Chrome
Installed Lucee 5.2.7.63 using installer
Installed MySQL 8.0.11 Community Edition using installer
Installed MySQL Workbench
Created a new schema via MySQL Workbench (which connects to MySQL just fine)
Created a datasource in Lucee server administrator which fails verification with:
Could not create connection to database server.
I tried using both a Lucee specific user, and the root user, and neither worked. When I checked the Lucee error log I saw this occur several times, once for each verification attempt:
Wed Jul 18 19:52:08 UTC 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
My guess is that I either need to force Lucee to use SSL, or force MySQL to allow a non SSL connection. Unfortunately, the Lucee administrator has no option related to SSL and doesn't allow me to modify the connect string manually. And I'm unsure how to alter settings for MySQL as I can't seem to find a my.ini file anymore.
The last time I setup a server was with MySQL 5.7 and I had no problems from start to finish, so I assume this must be a MySQL 5.8+ issue, but that is contradicted by the error message.
Update
In the end I decided to uninstall MySQL 8 and install MySQL 5.7. It was difficult to download the installer for 5.7 (I got 8 again the first time for some reason), and then there was a conflict with the MySQL installer, that didn't want to recognize the 5.7 I downloaded, but after getting through it all Lucee began connecting immediately with no problem.
I would still be interested in a solution, though, so that I can use MySQL 8 in the future.
You could try defining the datasource in your Application.cfc which will give you more control over the connection parameters. For example:
this.datasource = {
database: "mydatabase"
,type: "mysql"
,host: "hostname"
,port: 3306
,username: "myusername"
,password: "encryptedpassword"
,custom: {
useSSL: false
,useUnicode: true
,characterEncoding: "UTF-8"
}
};

Import MySQL data to Excel 365

I'm trying to import data from a MySQL Database to an Excel 365 (32 bit) Workbook.
This is a DB I can link to without any issues :
This is the DB I can't link to :
I've downloaded the following connector :
MySQL Connector Net 6.10.6
I suspect that this is not the correct connector for the second DB.
The error is this :
[MySQL: Unable to connect to any of the specified MySQL hosts.]
Could someone point me to the beginning of a solution ?
I've also tried to connect via VBA but I also get an error which must be due to the same causes as above.
If the database server and the database client (Excel) are running on different machines then they cannot communicate via UNIX filesystem sockets.
If you specify localhost as the target host in a libmysql client, then the client will try to connect via the (Unix) filesystem socket.
On the other hand, if you instead specify 127.0.0.1, it will use a TCP socket.
More Information:
Stack Overflow : How to connect to database when server is in Unix socket? (MySQL/PHP)
Wikipedia: Localhost
Wikipedia : Unix domain socket
Wikipedia : TCP Socket definition
MySQL.com : Configuring a Connector/ODBC DSN on Windows with the ODBC Data Source Administrator GUI
EDIT:
In response to your comment, the target host would be specified in the location specified on this page, or it can also be installed via command line with these steps.
Also you might find this helpful:
mysql.com : Using Connector/ODBC with Microsoft Word or Excel
mysql.com : Using Connector/ODBC with Microsoft Access
Setting up a MySQL ODBC DSN on Windows 7 64-bit:
I have a faint recollection of the last time I setup an ODBC DSN to MySQL.
It was a while ago so I might be mistaken on the details but I'm pretty sure that the only was I was able to get it working on a 64-bit system (possibly because the server was 32-bit?) was to install both the 32-bit and 64-bit drivers (from here) into separate folders, rebooting between each install. As I recall, it took a dozen install/uninstalls before I got it right.
Once it was properly installed, I had to administer it with Window's 32-bit version of ODBC Administrator.
There's 2 versions of ODBC Administrator (aka 'Data Sources'), confusingly:
My 64-bit version is located at : c:\windows\system32\odbcad32.exe
My 32-bit version is located at : c:\windows\SysWOW64\odbcad32.exe
Note that much of this is from memory and unverified!
I have this text file sitting in my "mySQL Notes" folder, so I gather I ended up using the command line to get it installed:
myodbc-installer -s -a -c1 -n " mysqlDSN " -t "DRIVER=MySQL ODBC 5.3 Unicode Driver;SERVER= (server name) ;DATABASE= (database name) ;UID= (user name) ;PWD= (password) "
In my case I was setting up connection to a web host server, so I referred to my CPanel for the server / database / uid values.
...and as I recall, I had to run it from the location of the 32-but version of the myodbc-installer. Also, you'll have an ODBC.INI text file somewhere showing the configuration.
More detail under the plethora of information here:
mysql.com : MySQL Connector/ODBC Developer Guide

Cannot connect to MySQL docker instance via DataGrip application

I have managed to successfully connect to a docker instance running MySQL via the mysql command line utility. However, I am struggling to do so via DataGrip application from JetBrains.
My mysql cli command is as follows:
mysql -h127.0.0.1 --port=8181 -uroot
The connection string that is generated in DataGrip is:
jdbc:mysql://127.0.0.1:8181
The error I am getting from DataGrip interface is:
[08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Is there anything that need to change in DataGrip that I am missing. I have read that the connection has to also be done via TCP. Not sure how to check that DataGrip is doing that.
Update: I eventually found the problem was the docker container I was using. It seems DataGrip is not able to connect to version 8.0.1 (mysql:8.0.1) mysql docker container. I tested using version 5.7 of the container and could successfully connect.
I was having an issue connecting MySQL 8.0.3 using DataGrip. You need to download the JDBC driver from Oracle website. Select Developer Releases (Since this is an unstable version). The 8.0.8 version worked for me. Download and save in a project folder or something similar on your computer. You will gonna need it later.
Go to DataGrip: File > DataSources. Click on the + and select Driver:
Screenshot of the Step above
On the section Driver Files > Additional files click on the + and select the jar file you just downloaded
After that on the Class dropdown select com.mysql.jdbc.Driver
Mark Dialect as MySQL
On the section URL templates, put the Name as default and Template as jdbc:mysql://{host::localhost}?[:{port::3306}][/{database}?][\?<&,user={user},password={password},{:identifier}={:identifier}>]
Click on apply
Done!
Screenshot of MySQL 8.0.3 running on Datagrip
Add a new datasource using the new driver.
If you find the following error:
[01S00] The server time zone value 'PDT' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support
You can do a temporary fix going to the Advanced tab and setting the serverTimezone variable for UTC as an example.
There are no *.jar-files anymore. Only *.deb-packages for my OS on the Oracle site https://dev.mysql.com/downloads/connector/j/5.1.html
So I selected driver Amazon Aurora MySQL for my MySQL 8.0.3 in docker.
It works!

Access MySQL server from Grails

I like to setup a dedicated MySQL server in a LAN accessible from other computers of this network. How can I setup the database server and the clients?
How can a Grails application can access the MySQL from the same LAN?
If your MySQL server is going to run on Windows then you can configure it with the installation program. For example, I downloaded the install file mysql-installer-community-5.6.20.0.msi (versions change quickly) and it offers the option of installing just the server:
Just follow the screen prompts and take all the default values (strongly recommended). The main values to remember are:
The default network port number 3306.
The server's ip address.
The username(s) and password(s) that you created that have access to
MySQL.
Then I suggest you download HeidiSQL and configure a connection to your new MySQL server, that way you can manage your database server remotely:
Hope that helps.
You are asking 2 differents questions.
To set up mysql connection in your grails app, did you at least try to read the doc ?
http://grails.org/doc/latest/guide/single.html#dataSource
It's just a jdbc connection string :
https://www.google.fr/?gws_rd=ssl#q=jdbc+mysql+connection+string+example
It's more than just the JDBC connect string. You won't get far without a driver, so uncomment the sample entry in BuildConfig.groovy in the dependencies section and update the version to the most recent:
dependencies {
...
runtime 'mysql:mysql-connector-java:5.1.34'
}
Set the driverClassName in DataSource.groovy, along with the correct JDBC url for your database. Replace <server> with the server name or IP address, and <dbname> with the correct database name. You will likely also want to add parameters at the end of the url in the querystring. And if the port is non-standard (3306 is the default) then add that in also. To ensure that you use INNODB tables (older versions of MySQL default to MyISAM), specify the MySQL5InnoDBDialect (or a subclass):
dataSource {
...
driverClassName = 'com.mysql.jdbc.Driver'
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
url = 'jdbc:mysql://<server>/<dbname>'
}
Run grails compile to download the driver jar and setup the classpath.