Apologies that I am working with inherited code and don't understand it well enough to create a minimal reproducible example.
The application is saving data to a MySQL database, through a JPA repository.
The application works, but the data is not apparent through a second application (eg DBeaver) until the MySQL server is restarted.
Is there something I need to set in MySlq (5.6.21) or is there some way I should be configuring the connection in my application to change this behavior?
I have the following in my application.yml:
spring:
lifecycle:
timeout-per-shutdown-phase: 5s
datasource:
password: MYPASS
url: jdbc:mysql://localhost:3306/myDB?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useServerPrepStmts=true
&rewriteBatchedStatements=true&cachePrepStmts=true
username: MYUSER
auto-commit: true
hikari:
auto-commit: true
jpa:
hibernate:
ddl-auto: none
use-new-id-generator-mappings: false
connection:
provider_disables_autocommit: false
Related
Currently, I have this in my springboot application.dev.yaml:
datasource:
url: jdbc:mysql://mysql/$DB_HOST?useSSL=false&allowPublicKeyRetrieval=true
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
I want to add a dynamic value in username, passwords, $DB_HOST field so that it can pick those values from the secrets file in Kubernetes.
The secrets file in Kubernetes is encrypted with base64
In Spring Boot, any property can be overridden by an environment variable of the same name, with the characters changed to upper case, and the dots changed to underscores.
For example datasource.url can be overridden by setting an environment variable like DATASOURCE_URL, which you define in Kubernetes
Source: https://developers.redhat.com/blog/2017/10/04/configuring-spring-boot-kubernetes-secrets#setup
Facing the following error when running WSO2 Analytics 3.1.0
The database connection is fine: Able to connect to the MYSQL DB
The Table is also present
Mysql version: 5.7
and sql connector: 5.1.42
deployment.yaml
#Data source for APIM Analytics
- name: APIM_ANALYTICS_DB
description: Datasource used for APIM Analytics
jndiConfig:
name: jdbc/APIM_ANALYTICS_DB
definition:
type: RDBMS
configuration:
jdbcUrl: 'jdbc:mysql://wso2db:3306/analytics3db?autoReconnect=true&useSSL=false'
username: 'xxxxxxx'
password: 'xxxxxxxxx'
driverClassName: com.mysql.jdbc.Driver
maxPoolSize: 50
idleTimeout: 60000
connectionTestQuery: SELECT 1
validationTimeout: 30000
isAutoCommit: false
tried different SQL connector, from .47, but still facing this issue
[2020-10-16 13:21:02,257] ERROR {io.siddhi.core.table.Table} - Error on 'APIMApiVersionUsageSummarySiddhi'. Failed to initialize store for table name 'ApiUserPerAppAgg_MONTHS' Error while connecting to Table 'ApiUserPerAppAgg_MONTHS', will retry in '10 sec'. io.siddhi.core.exception.ConnectionUnavailableException: Failed to initialize store for table name 'ApiUserPerAppAgg_MONTHS'
at io.siddhi.extension.store.rdbms.RDBMSEventTable.connect(RDBMSEventTable.java:1237)
at io.siddhi.core.table.record.AbstractQueryableRecordTable.connectAndLoadCache(AbstractQueryableRecordTable.java:206)
at io.siddhi.core.table.Table.connectWithRetry(Table.java:406)
at io.siddhi.core.table.Table$1.run(Table.java:422)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.siddhi.extension.store.rdbms.exception.RDBMSTableException: Error in looking up database type: HikariPool-5 - Connection is not available, request timed out after 30028ms.
at io.siddhi.extension.store.rdbms.util.RDBMSTableUtils.lookupDatabaseInfo(RDBMSTableUtils.java:422)
at io.siddhi.extension.store.rdbms.util.RDBMSTableUtils.lookupCurrentQueryConfigurationEntry(RDBMSTableUtils.java:453)
at io.siddhi.extension.store.rdbms.RDBMSEventTable.connect(RDBMSEventTable.java:1093)
... 10 more
Based on the logs, seems like there are no available connections. So as a solution you can increase the data source connection pool size and check.
ex:
maxPoolSize: 100
Also, make sure DB is supported max connection defined in the maxPoolSize. If not increase it in the DB too.
In here change the name section under jndiConfig into as following
name: jdbc/analytics3db
By changing this my connection is established with database.
- name: APIM_ANALYTICS_DB
description: Datasource used for APIM Analytics
jndiConfig:
name: jdbc/analytics3db
definition:
type: RDBMS
configuration:
jdbcUrl: 'jdbc:mysql://wso2db:3306/analytics3db?autoReconnect=true&useSSL=false'
username: 'xxxxxxx'
password: 'xxxxxxxxx'
driverClassName: com.mysql.jdbc.Driver
maxPoolSize: 50
idleTimeout: 60000
connectionTestQuery: SELECT 1
validationTimeout: 30000
isAutoCommit: false
Even check whether in .siddhi file in #store you have datasource as following
#store(type='rdbms',datasource="APIM_ANALYTICS_DB")
I am deploying a Spring Application on AWS OpsWork via a Chefbook read from an S3 bucket.Currently, I first have to create the mysql database called messagegateway. My application.yml file is as follows:
# database configuration
spring:
jpa:
show-sql: false
generate-ddl: false
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql:thin://localhost:3306/messagegateway
username: root
password: mysql
driver-class-name: org.drizzle.jdbc.DrizzleDriver
However, I want to create the messagegateway database from a script instead of manually creating it. I tried adding the following code snippet at the top of the InitialSetup.sql script (which creates the tables required by the application):
CREATE DATABASE IF NOT EXISTS messagegateway;
However, I get the following error:
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException
Caused by: org.h2.jdbc.JdbcSQLException
Any leads on how can I create the database via a script or configuration file?
So, I'm using the mysql2psql gem and I've got the following code:
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
username: root
password: root
database: hello_development
destination:
# if file is given, output goes to file, else postgres
file:
postgres:
hostname: localhost
port: 5432
username: root
password: root
database: hello_development
# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false
I'm a bit confused though, as to how I would convert all of my table e.g. test, and production as well. At the moment, it looks like I am just converting hello_development.
Please advice!
You're specifying which database to use - database: hello_development - which is why it's only running in your development environment. You need to create config files for mysql2pgsql for your test and production environments as well.
Having used mysql2pgsql in the past, keep in mind that there can be a LOT of differences between how mysql and postgres work - make sure that you have fully tested your application in a development environment prior to running this script in your production environment.
I have two databases, (MySQL and Oracle), I did the connection betweek sf2 and both databases, here is my config.yml file:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
sysman:
driver: %database_driver2%
host: %database_host2%
port: %database_port2%
dbname: %database_name2%
user: %database_user2%
password: %database_password2%
charset: UTF8
My question is, how can I run console command on the second database (Oracle), commands like (doctrine:database:create ...), and thanks
Use the --connection parameter:
php app/console doctrine:database:create --connection=default
or
php app/console doctrine:database:create --connection=sysman
You should first read a tutorial about commands and how to pass options and parameters to the commands. And how to distinguish between an option and a parameter.
If you want to make your own commands...
You will probably want to make it like this - if you do not pass an option (you will use the default database), if you pass it, you will make sure it is a valid option, and use the passed database connection name.
Doctrine is not tightly coupled with Mysql, you can use almost all most common available databases.
Also note, commands are container aware. That means you commands can access container, though which you have access to your services, such as doctrine:
protected function execute(InputInterface $input, OutputInterface $output)
{
$connection $input->getArgument('connection');
# Validate connection argument here and use it below
$container = $this->getContainer();
$em = $container->get('doctrine')->getManager(); // default db
$em = $container->get('doctrine')->getManager('sysman'); // another
return 1;
}
I wrote the code without testing, excuse me for any mistake I might have done.
php app/console doctrine:mapping:info --em=default (same without em option)
php app/console doctrine:mapping:info --em=sysman