I use database.properties to save my database information. However, it pop up this error, every time I run the code. I don't know which part of the database is wrong. Please help!
host: 127.0.0.1
port: 3306
database: spider
username: root
password: !QAZxsw2
driver: com.mysql.cj.jdbc.Driver
drivertype: MYSQL
ERROR Database:40 - java.sql.SQLNonTransientConnectionException:
Cannot load connection class because of underlying exception:
com.mysql.cj.exceptions.WrongArgumentException: Failed to parse the
host:port pair
'127.0.0.1:3306;databaseName=spider;user=root;password=!QAZxsw2;serverTimezone=UTC&'.
You seem to be using SQL Server JDBC driver syntax for the URL, while you are using the MySQL JDBC driver.
See MySQL Connector/J 8, Connection URL Syntax, the URL to connect to MySQL would be:
jdbc:mysql://127.0.0.1:3306/spider?user=root&password=!QAZxsw2&serverTimezone=UTC
Note that I also removed the & you had, which has no place in a URL, unless you are putting it in XML and want to escape the & between key-value pairs.
Given the syntax of JDBC URLs is undefined, except for the jdbc:<sub-protocol>: prefix, you cannot try to dynamically construct it like you are doing and expect it to work on different drivers. Each driver has their own syntax, and although there is considerable overlap in syntax, each has their own idiosyncrasies (if not outright outlandish syntax). Instead, use a single property for the entire URL, or use a driver-specific strategy.
After I post this question, I found out that my connection string was wrong. jdbc:mysql://localhost:%s/%s?serverTimezone=UTC&"+"user=%s&password=%s It should be like that url pattern of mysql.
Related
I'm trying to connect to a Google Cloud SQL second generation in Python from AppEngine standard (Python 2.7).
Until now, I was using MySQLDB driver directly and it was fine.
I've tried to switch to SQLAlchemy, but now I'm always having this error when the code is deployed (it seems to work fine in local) resulting in a error 500 (It's not just some connections which are lost, it constantly fails) :
OperationalError: (_mysql_exceptions.OperationalError) (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 38") (Background on this error at: http://sqlalche.me/e/e3q8)
I don't understand because the setup doesn't differ from before, so it must be related to the way I use SQLAlchemy.
I use something like this :
create_engine("mysql+mysqldb://appuser:password#x.x.x.x/db_name?unix_socket=/cloudsql/gcpProject:europe-west1:instanceName")
I've tried different values (with, without the ip, ...). But it is still the same. Is is a version compatibility problem ?
I use
MySQL-python in the app.yaml and SQLAlchemy 1.2.4 :
app.yaml :
- name: MySQLdb
version: "latest"
requirements.txt :
SQLAlchemy==1.2.4
It was a problem in the url. I was adding in a specific part of the code "/dbname" at the end of the connection string, resulting in something like this :
mysql+mysqldb://appuser:password#/db_name?unix_socket=/cloudsql/gcpProject:europe-west1:instanceName/dbname
So in the end, the meaning of this error can also be that the unix socket is wrong.
There are a number of causes for connection loss to Google CloudSQL server but quite rightly, you have to ensure that your setup is appropriate first. I don't think this issue is about version compatibility.
According to the documentation, for your application to be able to connect to your Cloud SQL instance when the app is deployed, you require to add the user, password, database, and instance connection name variables from Cloud SQL to the related environment variables in the app.yaml file(Your displayed app.yaml does not seem to contain these environment variables).
I recommend you review the details in the link for details on how to set up your CloudSQL instance and connecting to the instance.
I am working with ServiceStack evaluating the ORMLite provider with MySql for use on a.NET Core 1.1 project. I am running into a curious issue I am not sure what the problem is and looking for some guidance on how to troubleshoot this further or possible fixes.
I am running the .Net Core app in a standard docker container and MySql in the standard MySql container. I have been able to successfully run MySQL and connect with the workbench tool.
What I cannot do is get the executing code of the web application to successfully connect to the MySQL container. I have tried various combinations. Those where the IP Address or hostname were wrong I received a meaningful error saying the host was unknown.
But under scenarios where server name or IP address values that are used that are appropriate for the MySQL container, I receive a generic MySQLException error. The username and password are correct. I have even used the root account to ensure that there aren't any potential security hangups.
Here is a code snippet of where I am attempting to connect. This setup was working well using a local SQL db file, there is just something I am missing with either the configuration of Docker or MySQL that I haven't been able to isolate.
const string connectionString = "Server=3400f112c973:3306;Database=ServiceDB;Uid=root;Pwd=my-secret-pw;";
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(connectionString, MySqlDialect.Provider ));
using (var db = container.Resolve<IDbConnectionFactory>().Open())
{
if (db.CreateTableIfNotExists<TypeExample>())
{
//Add seed data
}
}
I have figured out my scenario.
In the MySQL Connection string, if you are using a non-standard port, you need to use the port parameter to specify the different port and omit the port entirely if using the standard port.
My issue was I was always using "Server=servername:port;" which is an incorrect format and should have been "Server=servername;Port=port;" in the cases where I was using a nonstandard port number, otherwise Port= can be omitted.
I'm trying to open a connection to a db via the DriverManager. When I use the getConnection(url, properties) function it works fine, however when I try to append the username and password (something like jdbc:mysql:address;user=user;password=password) to the url and call getConnection(url) I get the following error
Access denied for user ''#'localhost' to database 'db_aux_linux64_mysql;user=user;password=password'
So while it was able to find the db, it is trying to pass in an empty string as the user argument (and probably the password as well) for some reason. Any ideas on why this might be?
You're using the wrong url syntax, try this:
Connection conn = DriverManager.getConnection("jdbc:mysql://hostname/dbname?user=user&password=password");
Note: Don't forget to add your database name after your hostname -- the error message you are getting is indicating that the jdbc driver is looking for a database that is literally named "db_aux_linux64_mysql;user=user;password=password".
Alternatively, you can just use the DriverManager.getConnection(url, uname, pass) as suggested in the comments, then you don't need to remember the url syntax for your jdbc driver (and your code will be more portable since each jdbc driver is subject to having different url syntax).
Source: Mysql doc seciton 6.1
I've set up a MySQL db in Heroku, and successfully connected to it via MySQL Workbench.
I've been using felixge's node-mysql plugin to try and connect to it from my app (written in coffeescript), set up the connection as follows:
db = mysql.createConnection({
host: 'server-name.cleardb.com/heroku_randomletters?reconnect=true'
user: 'mysn'
password: 'mypwd'
})
Unfortunately I'm getting an Error: getaddrinfo ENOTFOUND in the console and the app crashes. I know the error's from this block of code because removing it works fine. Preliminary googling implied that this error is because the db URL is wrong, but it's copy pasted from what I put into MySQL Workbench and that's working fine. I've manually ran this chunk of code through js2coffee and it's being transpiled correctly, so it's not CS screwing up the object or anything, either.
Even though the information was all exactly the same, I got it to connect successfully and run a query by passing the information as a string instead of an object.
db = mysql.createConnection('mysql://mysn:mypwd#server-name.cleardb.com/heroku_randomletters?reconnect=true')
I'm not marking this as the answer because I'd still like to know why passing the information as an object was failing.
In case you haven't solved this:
Remove heroku_randomletters and reconnect=true from the host. Put heroku_randomletters as a database property instead.
I have installed a local server Xampp, which is running mySQL database in Windows. I created a Database on it with one table. The thing is I cannot get a connection to the database when I use the dbExpress TSQLConnection component. When I set the properties as follows:
ConnectionName = MYSQLConnection
Driver = MySQL
Database = databaseName
HostName = localhost
password =
UserName = root
When I change the connected property to true, I get the following error:
Borland.Data.TDBXError: DBX Error: Driver could not be properly initialized. Client library may be missing, not installed properly, of the wrong version, or the driver may be missing from the system path
I have tried making a connection to the database using the Data Explorer, but I still get the above error. I do not know what I'm missing or doing wrong.
Im using Delphi-XE2.
with mySQL on the server: MySQL client version: mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $.
I have also tried using an ADO connection, but I do not know how to set the connection string.
I'm still a noob and just want to learn how to make a connection to a mySQL database running on a web server. I cannot afford to buy any components.
Try this!
Did some google Fu - and stumpled upon this link : http://wiltonsoftware.com/posts/view/getting-embarcadero-dbexpress-mysql-working-dbx-error-driver-not-initialized
That seems to fit your needs.
My previous answer was no help .. hope the new one is better.
Old answer:
Make sure you have Data.DBXMySQL in your uses clause.
OK. I'll try a different approach.
Is it working if you setup the connection in the DataExplorer?
If not - then it's not a problem with the uses clause.
(and you obviously have tried that - sry . must be tired :-))
Otherwise a unit could be like this.
unit Unit1;
interface
uses // <-- Uses normally goes right after interface .... (you probably already have one)
Data.DBXMySql;
implementation
end.