I am using Knex.js for database connections. I would like to use a connection string instead of the connection object for connecting to a database and be able to specify the charset
.
Example:
connection: 'mysql://root:[email protected]:3306/test-db'
NOT
connection: {
host : '127.0.0.1',
user : 'root',
password : 'secret',
database : 'test-db',
charset : 'utf8'
}
I have the connection string working.
Could someone explain how I would specify the charset
in the Knex.js connection string?
I am using Knex.js for database connections. I would like to use a connection string instead of the connection object for connecting to a database and be able to specify the charset
.
Example:
connection: 'mysql://root:[email protected]:3306/test-db'
NOT
connection: {
host : '127.0.0.1',
user : 'root',
password : 'secret',
database : 'test-db',
charset : 'utf8'
}
I have the connection string working.
Could someone explain how I would specify the charset
in the Knex.js connection string?
-
1
Gadzooks!, yet another 3rd party package! If you can't figure it out, execute
SET NAMES utf8
right after connecting; that's usually a valid fallback. – Rick James Commented Jul 27, 2016 at 0:54 - The knex docs says that it passes the connection string directly to the underlying driver: knexjs/#Installation-client . If so, the underlying driver might not be showing the expected behavior: github./mysqljs/mysql#establishing-connections . I'm just guessing, but it may worth the try. – Sombriks Commented Jul 27, 2016 at 6:08
- Thanks, this is very helpful. The docs show the below connection string which looks promising: connection = mysql.createConnection('mysql://user:pass@host/db?debug=true&charset=BIG5_CHINESE_CI&timezone=-0700'); – Kevin Baker Commented Jul 27, 2016 at 7:32
1 Answer
Reset to default 6Try:
connection: 'mysql://root:[email protected]:3306/test-db?charset=utf8mb4'
See connection string options as described here: https://github./mysqljs/mysql#connection-options