Does MySQL Connector/J read ~/.my.cnf? - mysql

I have a Java application that uses MySQL with the Connector/J MySQL connector. I would like to specify the default client charset in the $HOME/.my.cnf file of the application user, so that it does not affect other applications on the same server.
To test whether Connector/J uses $HOME/.my.cnf, I created the file with the following content:
[client]
socket=/tmp/inexisting-mysql.sock
I expected that the Java application fails to connect to the database, because the /tmp/inexisting-mysql.sock does not exist. However, the application can still connect to the database successfully. It looks like Connector/J is not reading this configuration file at all.
How can I make Connector/J read the $HOME/.my.cnf? Or how can I specify a [client] section option for just my Java application, but not for other applications that use the same database?
Regards, Benedikt

To set the default client charset for a connection you can give that as a parameter to the connection itself:
jdbc:mysql://localhost:3306/sakila?useUnicode=true&characterEncoding=UTF-8
I don't think there is a way to make Connector/J read your $HOME/.my.cnf out of the box. You could read that file in the java application and set the url parameter accordingly though.

Related

Does the MySQL Command Line Interface (CLI) have connection environment variables?

Does the MySQL Command Line Interface (CLI) or "shell" offer the ability to establish a connection using environment variables? The PostgreSQL CLI psql does via libpq with connection variables:
PGHOST
PGPORT
PGDATABASE
PGUSER
PGPASSWORD
I know I can connect via command-line switches and a ~/my.cnf file, but I'm wondering if there is an environment variable option analogous to the way psql works. Thanks!
Yes, for some of them: https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html
MYSQL_HOST
MYSQL_TCP_PORT
There is no environment variable for the schema to use as the default schema. Client should specify that in the connection DSN, or else the USE schema statement after connecting.
There is no environment variable for the MySQL username.
MYSQL_PWD but this is deprecated and insecure and will be removed in a future version of MySQL. It's insecure for PostgreSQL for the same reason: another user can view your client's environment variables using ps.
It's more secure to use ~/.my.cnf, or you can specify a different option file to use. You can even store the username/password in an encrypted options file. See https://dev.mysql.com/doc/refman/8.0/en/option-files.html

Connect a Centura client application to SQL Server

I am new to Centura application configuration
When I try opening the windows client application, which has the Centura sql.ini configuration file. I get the below error.
Can anyone please help me understand the issue?
Error code: 401
Reason: FOR SQLBASE: The specified database cannot be found. SQLBase cannot find the file named "x:\dbdir\dbname\dbname.DBS" where x:\dbdir is either the default, c:\SQLBASE, or modified with the DBDIR SQL.INI configuration keyword. In a multiuser network configuration, this error indicates that your network is working correctly, but the database system was unable to locate the specified database filename.
FOR NON-SQLBASE DATABASES: This problem can also occur with a SQLGateway when leaving out the protocol type in the SERVERNAME parameter that the client uses to communicate with the gateway (like SQLNBIOS).
For example, SERVERNAME=SERVER33,SQLQUEUE DBNAME=DB2DBMS, SQLQUEUE, SQLNBIOS
will not allow a remote client process (using SQLNBIOS on the LAN to communicate with the SQLGateway machine) to connect to the SQLGateway machine.
For SPX connectivity from DOS or MS Windows to a Unixware SQLBase Server check for the omission of the "serverpath=..." parameter in the SQL.INI file under the client section.
Remedy: Verify the database file exists. The default drive letter and dbdirname is c:\SQLBASE unless overridden with a DBDIR SQL.INI configuration keyword parameter. Verify the DBDIR keyword is not missing or pointing to a wrong database directory. Verify the DBNAME keyword is specified for the named database. Verify the SERVER keyword is not missing or conflicting with other network server names. In your CONFIG.SYS file, verify at least 40 files set with the FILES=40 parameter. If the server was being initialized while the connection was tried, retry the connection after the server has initialized. If all of the above fails, try using a different database name or try connecting to the database in single user mode at the same machine. If you can connect with a local engine it probably indicates a network configuration error exists. If you can connect with a new database name it probably indicates a previously named database was never properly initialized.

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.

CloverETL mySQL Database SSL secure connection & Parameters

I am trying to make the connection to a remote mysql database in CloverETL Designer (Community Version)
Documentation with examples on this subject seem fragmented so I have tried to piece the bits together but I'm not use if they are correct. I would be grateful for any suggestions or further clarification on this subject.
Here is what I have so far:
The SSL Certificate
As an alternative VPN connection the server guys passed me the raw CA certificate, which I saved as a .crt file in the conn folder of the CloverETL workspace.
CloverETL Connections
I created a new DB connection and tested it was working without SSL
In the graph window I created a simple graph
Switching to Source View I added the parameter attribute to the connection code like this:
<Connection database="MYSQL" dbURL="jdbc:mysql://hostname/database_name" id="JDBC0" jdbcSpecific="MYSQL" name="CPM" parameters="ssl=${WORKSPACE}/conn/mysql_cpm_cert.crt" password="password" type="JDBC" user="username"/>
Then I tested the connection to the database by creating new metadata from a DB table
The problem is that I don't know if the connect is now secure or not.
Here's the list of resources that I used to piece together the information:
components:bulkloaders:mysql_data_writer [CloverETL wiki]
MySQL :: MySQL 5.0 Reference Manual :: 6.3.6.3 SSL Command Options
Thanks
CPM
Your setup almost certainly does not use ssl. Both links you posted are not usable - first describes bulk loader and second connection via command line client. But what you need is to configure JDBC. So I would use http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html section "Security."
I would set:
useSSL=true
requireSSL=true
You will do that by adding items in table (Custom JDBC properties) on second tab (Advanced) of Connection Wizard. In source it should appear like "jdbc.useSSL=true jdbc.requireSSL=true" not "parameters=".
Then connection should fail, because in your default java key store is missing your certificate. It can be imported via http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/keytool.html section "Importing Certificates"
I hope this helps.

How to set up a ColdFusion MySQL datasource over SSL?

Is there a way to set up a ColdFusion data source to connect to a MySQL server over a secure connection using SSL?
I don't see any obvious option to enable a SSL connection on the data source in CF administrator.
The only option I can think of is to use the "connection string" field.
This is for a current configuration that is set up. We have other options, but I am curious as to if this is possible. Thanks.
You would need to use the "other" option in the Drivers dropdown and build your own connection string. Here's an article I found on SSL for MySQL through JDBC drivers: http://www.razorsql.com/articles/mysql_ssl_jdbc.html
UPDATE: Here is another article with information on connecting via SSL and updating the keystore with certificate data. There is also some good content in the comments of the page: http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-using-ssl.html