i am creating an application using jhipter,i set mysql for dev and prod when i change the address in the datasource and the pom.xml for liquibase always i have the error Access denied for user 'root'#'localhost' (using password: YES)
I executed also GRANT ALL PRIVILEGES ON . TO 'root'#'localhost' but always the same error.
for pom.xml :
<configuration>
<changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
<diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/crud</url>
<defaultSchemaName>crud</defaultSchemaName>
<username>root</username>
<password>0000</password>
<referenceUrl>hibernate:spring:com.semah.crud.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
<verbose>true</verbose>
<logging>debug</logging>
</configuration>
for application-dev.yml :
spring:
profiles:
active: dev
include: swagger
devtools:
restart:
enabled: true
livereload:
enabled: false # we use Webpack dev server + BrowserSync for livereload
jackson:
serialization.indent_output: true
datasource:
driver: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/crud?useUnicode=true&characterEncoding=utf8&useSSL=false
name: crud
username: root
password: 0000
hikari:
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
When using a password that contains only numbers, you need to add quotes around it is interpreted as a String value.
password: "0000"
Related
I am trying to get switch user feature in spring security to work. I am using grails 4.0.10 and mysql 8.
I created a sample hello world grails app and followed the switch user guide from the documentation. https://grails.github.io/grails-spring-security-core/4.0.x/index.html#switchUser
If i use the default h2 database then it works but if i switch to the mysql 8 database it is throwing page not found 404 error and it is not switching.
i have published the code in github. here is the link.
https://github.com/sanjaygir/switching
I have created a simple page in secure controller. The page is index.gsp that has a form to switch to another user. Logged in user should be displayed at the top of this page. In bootstrap file i have created two users. one admin and another regular user.
i have a local database with this configuration
dataSource:
dbCreate: create
url: jdbc:mysql://localhost:3307/switch?useUnicode=yes&characterEncoding=UTF-8
username: root
password: password
In order to run this app you need a mysql 8 db running. please change the mysql db name and username and password in the above section in application.yml.
After the app fires please go directly to http://localhost:8080/secure/index and then enter in the textbox "user" and click on the button switch. It will throw an error page not found and if you go back to http://localhost:8080/secure/index you can not see at the top loggedin user name. That means the switch was not successful.
here is the simple code for secure/index.gsp
<%# page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title></title>
</head>
<body>
<sec:ifLoggedIn>
Logged in as <sec:username/>
</sec:ifLoggedIn>
<form action='${request.contextPath}/login/impersonate' method='POST'>
Switch to user: <input type='text' name='username'/> <br/>
<input type='submit' value='Switch'/>
</form>
</body>
</html>
i hope i have made it clear. this is a simple hello world app created to see switch user feature i n action. I am puzzled why switch user works with default h2 db but not when connected to mysql 8. if anyone have any idea i appreciate your help. Thanks
UPDATE:
Today i switched the database to mysql version 5 and it works.
I changed the following configuration in application.yml
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: root
password: 'password'
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:mysql://localhost:3306/switch?useUnicode=yes&characterEncoding=UTF-8
in build.gradle i used
runtime 'mysql:mysql-connector-java:5.1.19'
still i am not sure why it doesnt work in mysql 8.
i finally found the bug. i cannot believe what caused the 404 not found issue.it was a single line in the configuration file.
before the application.yml looked like this
---
grails:
profile: web
codegen:
defaultPackage: rcroadraceweb4
gorm:
reactor:
# Whether to translate GORM events into Reactor events
# Disabled by default for performance reasons
events: false
info:
app:
name: '#info.app.name#'
version: '#info.app.version#'
grailsVersion: '#info.app.grailsVersion#'
spring:
jmx:
unique-names: true
main:
banner-mode: "off"
groovy:
template:
check-template-location: false
devtools:
restart:
additional-exclude:
- '*.gsp'
- '**/*.gsp'
- '*.gson'
- '**/*.gson'
- 'logback.groovy'
- '*.properties'
management:
endpoints:
enabled-by-default: false
server:
servlet:
context-path: '/roadrace'
---
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
grails:
plugin:
databasemigration:
updateOnStart: true
updateOnStartFileName: changelog.groovy
controllers:
upload:
maxFileSize: 2000000
maxRequestSize: 2000000
mail:
host: "localhost"
port: 25
default:
to: 'root#localhost'
from: 'noreply#runnercard.com'
dataSource:
type: com.zaxxer.hikari.HikariDataSource
pooled: true
driverClassName: com.mysql.cj.jdbc.Driver
dialect: org.hibernate.dialect.MySQL8Dialect
dbCreate: none
properties:
minimumIdle: 5
maximumPoolSize: 10
poolName: main-db
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
useLocalSessionState: true
rewriteBatchedStatements: true
cacheResultSetMetadata: true
cacheServerConfiguration: true
elideSetAutoCommits: true
maintainTimeStats: false
dataSources:
logging:
# This is not used unless `useJdbcAccessLogger` or `useJdbcLogger` is set to `true`
# This does not need to be setup unless it is in use.
type: com.zaxxer.hikari.HikariDataSource
pooled: true
driverClassName: com.mysql.cj.jdbc.Driver
properties:
minimumIdle: 2
maximumPoolSize: 5
poolName: logging-db
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
useLocalSessionState: true
rewriteBatchedStatements: true
cacheResultSetMetadata: true
cacheServerConfiguration: true
elideSetAutoCommits: true
maintainTimeStats: false
environments:
development:
dataSource:
dbCreate: none
url: jdbc:mysql://localhost:3307/dev2?useUnicode=yes&characterEncoding=UTF-8
username: root
password: password
grails:
# mail:
# host: "smtp.gmail.com"
# port: 465
# username: "justforstackoverflow123#gmail.com"
# password: "1asdfqwef1"
# props:
# "mail.smtp.auth": "true"
# "mail.smtp.socketFactory.port": "465"
# "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory"
# "mail.smtp.socketFactory.fallback": "false"
test:
dataSource:
# dialect: org.hibernate.dialect.MySQL5InnoDBDialect
dbCreate: none
url: jdbc:mysql://localhost:3307/test?useUnicode=yes&characterEncoding=UTF-8
username: root
password: password
production:
---
logging:
level:
root: INFO
org.springframework: WARN
grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition: ERROR
grails.plugins.DefaultGrailsPluginManager: WARN
org.hibernate: ERROR # TODO: we need to lower this, and fix the warnings this is talking about.
rcroadraceweb4: DEBUG
com.runnercard: DEBUG
liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator: ERROR
---
#debug: true
#useJdbcSessionStore: true
---
environments:
nateDeploy:
behindLoadBalancer: true
grails:
insecureServerURL: 'https://nate-dev.nate-palmer.com/roadrace'
serverURL: 'https://nate-dev.nate-palmer.com/roadrace'
dataSource:
url: 'jdbc:mysql://10.1.10.240:3306/rcroadwebDEV?serverTimezone=America/Denver'
after the fix it looks like this
---
grails:
profile: web
codegen:
defaultPackage: rcroadraceweb4
gorm:
reactor:
# Whether to translate GORM events into Reactor events
# Disabled by default for performance reasons
events: false
info:
app:
name: '#info.app.name#'
version: '#info.app.version#'
grailsVersion: '#info.app.grailsVersion#'
spring:
jmx:
unique-names: true
main:
banner-mode: "off"
groovy:
template:
check-template-location: false
devtools:
restart:
additional-exclude:
- '*.gsp'
- '**/*.gsp'
- '*.gson'
- '**/*.gson'
- 'logback.groovy'
- '*.properties'
management:
endpoints:
enabled-by-default: false
server:
servlet:
context-path: '/roadrace'
---
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
grails:
plugin:
databasemigration:
updateOnStart: true
updateOnStartFileName: changelog.groovy
controllers:
upload:
maxFileSize: 2000000
maxRequestSize: 2000000
mail:
host: "localhost"
port: 25
default:
to: 'root#localhost'
from: 'noreply#runnercard.com'
dataSource:
type: com.zaxxer.hikari.HikariDataSource
pooled: true
driverClassName: com.mysql.cj.jdbc.Driver
dialect: org.hibernate.dialect.MySQL8Dialect
dbCreate: none
properties:
minimumIdle: 5
maximumPoolSize: 10
poolName: main-db
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
useLocalSessionState: true
rewriteBatchedStatements: true
cacheResultSetMetadata: true
cacheServerConfiguration: true
elideSetAutoCommits: true
maintainTimeStats: false
dataSources:
logging:
# This is not used unless `useJdbcAccessLogger` or `useJdbcLogger` is set to `true`
# This does not need to be setup unless it is in use.
type: com.zaxxer.hikari.HikariDataSource
pooled: true
driverClassName: com.mysql.cj.jdbc.Driver
properties:
minimumIdle: 2
maximumPoolSize: 5
poolName: logging-db
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
useLocalSessionState: true
rewriteBatchedStatements: true
cacheResultSetMetadata: true
cacheServerConfiguration: true
elideSetAutoCommits: true
maintainTimeStats: false
environments:
development:
dataSource:
dbCreate: none
url: jdbc:mysql://localhost:3307/dev2?useUnicode=yes&characterEncoding=UTF-8
username: root
password: password
# grails:
# mail:
# host: "smtp.gmail.com"
# port: 465
# username: "justforstackoverflow123#gmail.com"
# password: "1asdfqwef1"
# props:
# "mail.smtp.auth": "true"
# "mail.smtp.socketFactory.port": "465"
# "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory"
# "mail.smtp.socketFactory.fallback": "false"
test:
dataSource:
# dialect: org.hibernate.dialect.MySQL5InnoDBDialect
dbCreate: none
url: jdbc:mysql://localhost:3307/test?useUnicode=yes&characterEncoding=UTF-8
username: root
password: password
production:
---
logging:
level:
root: INFO
org.springframework: WARN
grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition: ERROR
grails.plugins.DefaultGrailsPluginManager: WARN
org.hibernate: ERROR # TODO: we need to lower this, and fix the warnings this is talking about.
rcroadraceweb4: DEBUG
com.runnercard: DEBUG
liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator: ERROR
---
#debug: true
#useJdbcSessionStore: true
---
environments:
nateDeploy:
behindLoadBalancer: true
grails:
insecureServerURL: 'https://nate-dev.nate-palmer.com/roadrace'
serverURL: 'https://nate-dev.nate-palmer.com/roadrace'
dataSource:
url: 'jdbc:mysql://10.1.10.240:3306/rcroadwebDEV?serverTimezone=America/Denver'
it was this line in environments > development block
# grails:
it worked after commenting the grails line.
but all the contents of grails block is commented so i am still confused why having grails uncommented would have this big issue. anyways solved after days of hard search!
in my settings I can connect the flyway, it does the migrations more when I use the command maven flyway::repair it only works if I put the bank settings in pom.xml, I would like to have these settings in my .yml but i tried every way and i always get the error:
Unable to connect to the database. Configure the url, user and password!
meu .yml i try this forms
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
password: ${MYSQL_PASSWORD}
url: jdbc:${MYSQL_ENDPOINT}?serverTimezone=UTC&useSSL=false
username: ${MYSQL_USER}
jpa:
generate-ddl: false
open-in-view: false
hibernate:
ddl-auto: none
show-sql: true
properties:
hibernate:
generate_statistics: true
rabbitmq:
host: ${URI_DEV}
password: ${PASSWORD_DEV}
port: ${PORT_DEV}
username: ${USER_DEV}
flyway:
url: jdbc:${MYSQL_ENDPOINT}?serverTimezone=UTC&useSSL=false
user: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
enabled: true
in addition I also tried adding
flyway:
url: jdbc:${MYSQL_ENDPOINT}?serverTimezone=UTC&useSSL=false
user: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
but not work. how do you configure it to use the command flyway::repair with the connection data through .yml?
i'm trying to connect to my db in codeception. provided following configurations in my api.suite.dist.yml and codeception.dist.yml file (i didn't know where to provide configurations so i provide in both api.suite.dist.yml and codeception.dist.yml)
here is my api.dist.suite.yml
class_name: ApiTester
modules:
enabled:
- PhpBrowser:
url: http://192.168.1.143
- REST:
depends: PhpBrowser
url: https://dev-tv.dna.fi/api/user/guest/epg
- \Helper\Api
- Db:
dsn: 'mysql:host=127.0.0.1;dbname=db'
user: 'username'
password: 'passsword'
and here is my codeception.dist.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: 'mysql:host=127.0.0.1;dbname=db'
user: 'username'
password: 'password'
and this is the response i get
[Codeception\Exception\ModuleException]
Db: SQLSTATE[28000] [1045] Access denied for user 'webapiuser'#'localhost' (using password: YES) while creating PDO connection
run [-c|--config CONFIG] [--report] [--html [HTML]] [--xml [XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--] [] []
Don't use codeception.yml. Configuration in api.suite.yml is enough.
Make sure you use right credentials.
My acceptance.suite.yml
class_name: WebGuy
modules:
enabled:
- Db
config:
Db:
dsn: mysql:host=127.0.0.1;dbname=mydbname
user: myuser
password: mypass
populate: false
cleanup: false
I am haveing problem using MySql with Grails 3 project.
My Application.yml
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: root
password: *****
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:mysql://localhost:3306/mydb
also tried
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:mysql://localhost/mydb
My Build.gradle
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
------
runtime 'mysql:mysql-connector-java:5.1.32'
then did a "--refresh-dependencies"
ran the project I get this error:
ERROR org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254) ~[tomcat-jdbc-7.0.55.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182) ~[tomcat-jdbc-7.0.55.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701) [tomcat-jdbc-7.0.55.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635) [tomcat-jdbc-7.0.55.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486) [tomcat-jdbc-7.0.55.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144) [tomcat-jdbc-7.0.55.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116) [tomcat-jdbc-7.0.55.jar:na]
what am I doing wrong?
on the grails2.x there was a lib folder where I can drop a downloaded mysql-connector-java-5.1.32.jar file but on grails 3.x lib folder is missing. please help.:(
1) Add this to build.gradle
runtime "mysql:mysql-connector-java:5.1.24"
2) then in application.yml file replace H2 database with similar to these lines
dbCreate: update
driverClassName: com.mysql.jdbc.Driver"
dialect: "org.hibernate.dialect.MySQL5InnoDBDialect"
url: jdbc:mysql://localhost/mydbname?useUnicode=yes&characterEncoding=UTF-8"
username: "myusername"
password: "mypassword"
So I'be been working on a symfony2 project and it was all good, then i wanted to host it on godaddy but now I get this error. I don't understand it neither do I know how to fix it. thanks so much.
SQLSTATE[HY000] [1045] Access denied for user 'root'#'127.0.0.1' (using password: NO)
This is my paramaters.yml file
# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password:
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: 14bcde878eda1c3f56a59b62b13e820b7f94563d
This is my config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
translator: ~
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
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%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: CurrencyConverter\ConverterBundle\Entity\User1
sensio_framework_extra:
view:
annotations: false
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
I got the password and username now I get:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
Your database_user and database_password values need to be set in the parameters.yml file. You can get those settings in the GoDaddy new account setup email that gets provided to you.
The error message you got is clear enough,
SQLSTATE[HY000] [1045] Access denied for user 'root'#'127.0.0.1'
(using password: NO)
You need to set the right database_user & database_password in the parameters.yml used in your host. Check your accont configuration to get the right access parameters.
It depends on your hosting provider then . Sometimes when you have a shared server hosting the username is not root it could be {YOURGODADDYACCOUNT_root} or somthing. check your cpanel or plesk administration to get the right credentials.
As error message said. You need to provide some password. In my case, I just added 'root' for the password in parameters.yml file:
...
database_user: root
database_password: root
...
I changed database_host parameter in app/config/parameters.yml to 0.0.0.0 and this error disappeared.