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
I am trying to install Knowage to my Centos VM in command line and get the following error:
WARNING: please provide a database user that can create schemas. The
following schemas will be created (or overwritten):
knowage_demo
foodmart_demo
JDBC connection failed Database Management System Configuration Use an
already installed DBMS [1, Enter]
Select DBMS for metadata:
MariaDB [1, Enter]
MySQL [2]
2
[jdbc:mysql://localhost:3306]
Username: [root]
Password:
WARNING: please provide a database user that can create schemas.
Any ideas on how to make it working? It keeps getting back to this step.
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?
I'm following the instruction here to deploy my ruby on rails app on elastic beanstalks
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Ruby_rails.html
But I got following error when creating RDS database:
2014-04-19 18:35:49 INFO Creating RDS database named: aa8njgjixa22x5. This may take a few minutes.
2014-04-19 18:45:17 ERROR Creating RDS database: aa8njgjixa22x5 failed Reason: Cannot upgrade mysql from 5.6.13 to 5.5.33
2014-04-19 18:45:36 ERROR Stack named 'awseb-e-qzjpemepuc-stack' aborted operation. Current state: 'CREATE_FAILED' Reason: The following resource(s) failed to create: [AWSEBRDSDatabase].
2014-04-19 18:45:39 INFO Launched environment: drinkchatbackend-master. However, there were issues during launch. See event log for details.
Description :
2014-04-19 18:45:36 ERROR Stack named 'awseb-e-qzjpemepuc-stack' aborted operation. Current state: 'CREATE_FAILED' Reason: The following resource(s) failed to create: [AWSEBRDSDatabase].
2014-04-19 18:45:17 ERROR Creating RDS database: aa8njgjixa22x5 failed Reason: Cannot upgrade mysql from 5.6.13 to 5.5.33
Running "eb status --verbose" shows below
RDS Database: AWSEBRDSDatabase | aa8njgjixa22x5.cuokqzbpcqzr.us-west-1.rds.amazonaws.com:3306
Database Engine: mysql 5.6.13
Allocated Storage: 5
Instance Class: db.t1.micro
Multi AZ: False
Master Username: drinkchat
Creation Time: 2014-04-19 18:40:43
DB Instance Status: available
My .elasticbeanstalk/optionsettings080 config does not specifying 5.5.x
[aws:rds:dbinstance]
DBDeletionPolicy=Snapshot
DBEngine=mysql
DBInstanceClass=db.t1.micro
DBSnapshotIdentifier=drinkchatstaging-final-snapshot
DBUser=ebroot
Questions I have:
why it is trying to update to mysql 5.5.33?
how can I proceed investigation? I don;t see the application in
https://console.aws.amazon.com
I can't find the DB instance in the Amazon RDS console.
The work around I used was to not use elastic beanstalk's RDS configuration. instead just launch RDS manually and connect through my app.
How would I connect to my VPS based MySQL database remotely (from a cloud based app) using the Ruby Net::SSH or Net::SSH::Gateway gems and key, not password, authentication?
And then connect to the database with Sequel or DataMapper. I'm assuming that after I manage to get the SSH connection working, I would just setup a Sequel/DM connection to 'sql_user#localhost:3306/database'.
I did locate a couple of similar question here, but they all use password authentication, not keys, and only demonstrate executing raw commands to query the database.
UPDATE: I just cannot seem to get this (Net::SSH with key manager) to work.
UPDATE2: Alright I have managed to get authorization when logging in from a computer that has authorized keys stored in the users local .ssh folder, with the following (port is my custom SQL port on the VPS):
sql_gate = Net::SSH::Gateway.new('192.xxx.xxx.xx','sqluser', port: 26000)
However, I will not be able to create a .ssh folder in the app's VM, so I need to somehow pass the path and filename (I will be creating a public key just for SQL access for specified user) as an option ... but haven't been able to figure out how.
UPDATE: Just need to figure out DataMapper access now. Current code being tested (remote_user_sql is my Ubuntu user, sql_user is the MySQL database user with localhost/127.0.0.1 privileges):
require 'net/ssh/gateway'
require 'data_mapper'
require 'dm-mysql-adapter'
class User
include DataMapp......
.
.
end
ssh_gate = Net::SSH::Gateway.new('192.n.n.n','remote_user_sql', {port: 25000, keys: ["sql_rsa"], keys_only: true})
port = ssh_gate.open('localhost',3306,3307)
child = fork do
DataMapper.setup(:default, {
adapter: 'mysql',
database: 'sql_test',
username: 'sql_user',
password: 'passwd',
host: 'localhost',
port: port})
DataMapper.auto_upgrade!
exit
end
puts "child: #{child}"
Process.wait
ssh_gate.close(port)
My solution, in two parts:
Well I have figured how to make the Net::SSH::Gateway gem using a specified keyfile, and then connect to the VPS through ssh via a port other than 22:
Part 1: Net::SSH::Gateway key authentication
First you must generate the keyfiles you want to use, copy the .pub to the remove server and append it to the ~/.ssh/authorized_keys file (cat sql_rsa.pub >> authorized_keys), and then make sure user_sql (the user I created on the VPS to be used only for this purpose) has been added to AllowUsers list in sshd_config. Make note of port used for ssh (25000 for this example) and use the following code to establish the connection:
ssh_gate = Net::SSH::Gateway.new('192.n.n.n','user_sql', {port: 25000, keys: ["sql_rsa"], keys_only: true})
That will read the keyfile sql_rsa in the same directory as script file, then create a new ssh gateway for 'user_sql'#'192.n.n.n' on port 25000.
I can successfully execute raw shell commands on the remove VPS with:
ssh_gate.exec("ls -la")
To close:
ssh_gate.shutdown!
Unfortunately I am still having problems using DataMapper (do-mysql-adapter) to use the gateway. I will update this answer if I figure that part out, but at least the first half of the problem has been solved.
These are the errors that DataMapper::Logger has reported:
When 127.0.0.1 was used:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (code: 2002, sql state: HY000, query: , uri: )
When localhost was used:
Access denied for user 'user_sql'#'localhost' (using password: YES) (code: 1045, sql state: 28000, query: , uri: )
When the VPS hostname was used:
Unknown MySQL server host 'hostname' (25) (code: 2005, sql state: HY000, query: , uri: )
UPDATE (No success yet): So far the only way I can access the remote MySQL database is by using Net::SSH::Gateway to establish a gateway, and then use the .sshmethod to open a new Net::SSH connection over that gateway, like so:
ssh_gate.ssh('192.n.n.n','user_sql',{port: 25000, keys: ["sql_rsa"], keys_only: true}) do |ssh|
ssh.exec("mysql -u sql_user -p'passwd' -h localhost -P 3306 -e 'SELECT DATABASE();'")
end
In other words, I can only execute SQL commands using the mysql command line. I cannot figure out how to get Sequel or DataMapper to use the gateway to connect.
Part 2: DataMapper/Sequel/mysql2 connection through Net::SSH::Gateway
Make sure your MySQL server is bound to 127.0.0.1 in /etc/mysql/my.cnf, setup your connection - DataMapper example:
DataMapper.setup(:default, {
adapter: 'mysql',
database: 'DATABASE',
username: 'username',
password: 'passwd',
host: '127.0.0.1',
port: 3307}) # local port being forwarded via Net::SSH:Gateway
Followed by any class table definitions and DataMapper.finalize if required. Note that DataMapper doesn't actually connect to the remote MySQL server until either an auto_upgrade!, auto_migrate!, or query is executed, so no need to create the forwarded port yet.
Then create a new Net::SSH::Gateway, and then whenever you need DataMapper/Sequel to access the remote database, just open a port for the process, like so:
port = ssh_gate.open('127.0.0.1',3306,3307)
child = fork do
DataMapper.auto_upgrade! # DM call that accesses MySQL server
exit
end
Process.wait
ssh_gate.close(port)
You may want to put the Net::SSH::Gateway/.open code in a begin..ensure..end block, ensure'ing the port closure and gateway shutdown.
I had to use a fork and Process.wait to establish the connection, without it the method just hangs.