How catch MySQL error in Repo.start_link (Phoenix\Elixir) - mysql

When I do Repo.start_link with incorrect credential I got state :ok
{state, pid} =
MyApp.Repo.start_link(
name: nil,
hostname: hostname,
username: username,
password: password,
database: db_name,
pool_size: 1
)
state and pid = {:ok, #PID<0.551.0>}
But in the logs I got
[error] MyXQL.Connection (#PID<0.554.0>) failed to connect: ** (MyXQL.Error) (1045) (ER_ACCESS_DENIED_ERROR) Access denied for user 'username'#'localhost' (using password: YES)
How I can get error message in {state, pid}?

You can start another Repo without a name, but you can't access it directly, all operations are sent to the default repository Myapp.Repo.
You can also start repositories without names by explicitly setting
the name to nil:
MyApp.Repo.start_link(name: nil, hostname: "temp.example.com")
However, once the repository is started, you can't directly interact with
it, since all operations in MyApp.Repo are sent by default to the repository named MyApp.Repo.
Source: https://github.com/elixir-ecto/ecto/blob/v3.6.2/lib/ecto/repo.ex#L554

Related

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'root'#'localhost' (using password: YES)")

I have used SQLalchemy in python3 to connect to local MySQL.
However, I got such error: sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
The password is the same as in MySQL workbench, that is "root", I do not know why I got this error.
My code:
engine = create_engine("mysql+pymysql://root:root#localhost/db?host=localhost?port=3308", echo=True)
with engine.connect() as conn, conn.begin():
book_df.to_sql(name='test', con=conn, if_exists='append', index=False)
Already answered at the top, but if you want connect to RDS and if you have special characters in your password like "#" be sure to use urllib.parse.quote or else you will encounter the same error.
import urllib
user = "user"
password = urllib.parse.quote("p#ssword")
endpoint = "rds_endpoint"
port = "port"
db = "db_name"
engine = create_engine(f"mysql+pymysql://{user}:{password}#{endpoint}:{port}/{db}", echo=True)

springboot,Can't connect to my database java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)

java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
Process finished with exit code -1
my test
#SpringBootTest
class Springboot04DataApplicationTests {
#Autowired
DataSource dataSource;
#Test
void contextLoads() throws SQLException {
System.out.println(dataSource.getClass());
Connection connection = dataSource.getConnection();
System.out.println(connection);
}
}
here is my application.yml
spring:
datasource:
username: root
password: 011575
url: jdbc:mysql://localhost:3306/mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true
driver-class-name: com.mysql.cj.jdbc.Driver
I confirmed that my username is root and my pwd is 011575.And also open the mysql service, please help me!!
When springboot reads the data in yml, it will read the pure digital data starting with the number 0 in binary, octal or decimal, and the read value will be different from the original stored value.
so just change your application.yml like this:
password: "011575"
The username and password should be like this
username: root
password: "011575"

sequelize dialectoptions , UTC and dates, for mysql

I am still learning how to use sequelize.
I am using sequelize 5 along with node 10 and mysql2 .
I am setting my connection like so
const sequelize = new Sequelize({
database: dbs,
username: usr,
host: hst,
password: pwd,
port: prt,
dialect: 'mysql',
dialectOptions: {
useUTC: true,
dateFirst: 1
},
define:{
timestamps:false,
paranoid:false,
freezeTableName: true
}
});
and I am getting the following warnings
Ignoring invalid configuration option passed to Connection: useUTC.
This is currently a warning, but in future versions of MySQL2, an
error will be thrown if you pass an invalid configuration option to a
Connection
Ignoring invalid configuration option passed to Connection: dateFirst.
This is currently a warning, but in future versions of MySQL2, an
error will be thrown if you pass an invalid configuration option to a
Connection
If I remove the useUTC: true and dateFirst: 1 from the dialectOptions, the errors obviously go away.
What am I missing and how can I set those options for mysql

why spring-boot can't connect to local mysql server(Access denied for user 'root'#'localhost' (using password: YES))

I encountered a very strange phenomenon about Spring boot and use mysql to store data, today in my private computer I git cloned my developing project. When run the entry main class in eclipse, it throws exception
2015-11-15 18:28:08.912 ERROR 9183 --- [ restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1665) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1207) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2249) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2280) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) ~[mysql-connector-java-5.1.36.jar:5.1.36]
it's application.properties :
spring.datasource.url = jdbc:mysql://localhost:3306/foo?useUnicode=true&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 123456
but I could login mysql directly in terminal, see below:
mysql -hlocalhost -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.6.27-0ubuntu0.14.04.1 (Ubuntu)
and I even write a sample java code in the same project to test connection with local mysql server,
public static void main(String[] args) throws SQLException {
String url = "jdbc:mysql://localhost:3306/foo?useUnicode=true&characterEncoding=utf8";
String user = "root";
String password = "123456";
Connection connection = DriverManager.getConnection(url , user , password);
System.out.println(connection);
Statement stat = connection.createStatement();
ResultSet rs = stat.executeQuery("select version()");
rs.next();
System.out.println(rs.getString(1));
}
Run it have normal output:
com.mysql.jdbc.JDBC4Connection#48cf768c
5.6.27-0ubuntu0.14.04.1
So why spring-boot can't connect to local mysql server, but other ways could?

SQLSTATE[HY000] [1045] Access denied for user 'root'#'127.0.0.1' (using password: NO) SYMFONY2

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.