FreeTDS UTF-8 insert in mysql - mysql

I have a linux server with mysql with symfony framework installed.
Now i'm trying to get data from sql server 2012 and all works great except when i try to insert value in mysql database.
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\x80 IN P...' for column 'note_anagrafica' at row 1
Seems that the problem is on data conversion.
The data type of column inside mysql where i'm trying to insert the data is:
text
And the collation is:
utf8_unicode_ci
FreeTds configuration is set on UTF-8 and driver is odbc.
Someone have a solution for this problem?
EDIT:
odbc.ini
[server]
Driver = FreeTDS
Server = x.x.x.x
Port = 1234
Database = databasename
TDS_Version = 8
client charseg = UTF-8
server charset = CP1252
freetds.conf
[server]
host = x.x.x.x
port = 1234
tds version = 8.0
client charset = UFT-8
text size = 20971520
use uft-16 = true
doctrine config for mysql.
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
doctrine config for external mssql database:
server:
driver_class: Lsw\DoctrinePdoDblib\Doctrine\DBAL\Driver\PDODblib\Driver
host: "%a_database_host%"
port: "%a_database_port%"
dbname: "%a_database_name%"
user: "%a_database_user%"
password: "%a_database_password%"
charset: utf8mb4
from now i'm getting error when i'm trying to insert data to mysql comes from sql server 2012 with doctrine.
Till now i have no problem on reading execpt that if i out the result on the web the special charaters like ø comes with � symbol.
There is a conversion that i have to made before call
$entityManager->persist($object);
$entityManager->flush();

Set the charset to utf8mb4 for doctrine config and will do the trick.

Related

Can't change character-set-client & character-set-connection from utf8mb4 to utf8 using JDBC for mysql 5.6

I've this connection string & it was working fine with mysql Connector/J 5.1.40 and mysql 5.5 on windows:
jdbc:mysql://localhost:3306/db?noAccessToProcedureBodies=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&connectionCollation=UTF8_PERSIAN_CI
but when I upgraded to mysql 5.6, It seems that JDBC driver automatically changes connection encoding from utf8 to utf8mb4 according to the mysql change history :
Connector/J now auto-detects servers configured with character_set_server=utf8mb4 or treats the Java encoding utf-8 passed using characterEncoding=... as utf8mb4 in the SET NAMES= calls it makes when establishing the connection. (Bug #54175)
I don't know why it should treat utf8 as utf8mb4, but I even can't change it manually after connection established:
Statement stmt = (Statement) conn.createStatement();
stmt.executeQuery("SET NAMES UTF8 COLLATE UTF8_PERSIAN_CI");
stmt.close();
which has no effect on connection state parameters & I've still following situation:
character-set-client=utf8mb4
character_set_connection=utf8mb4
character_set_database=utf8
character_set_filesystem=binary
character_set_results=utf8
character_set_server=utf8
character_set_system=utf8
This is part of mysql config file:
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqld]
character-set-server=utf8
collation-server = utf8_persian_ci
I really need to change connection encodig to utf8 instead of utf8mb4 because it made some problems in my application.
Any workaround would be appreciated.

mysql change default character set latin1 to utf8

I have PHP 5.5.9 and MySQL 5.5.43 Innodb. This is in Kubuntu LTS /etc/mysql/my.cnf
printf("Current character set: %s\n", mysqli_character_set_name($conn));
Current character set: latin1
I've tried
default-character-set = utf8
first but then my mysql server didn't restart
Then I've tried
character-set-server = utf8
then my mysql shell didn't start
How can I rescue this issue? I've managed with
init_connect = 'SET NAMES utf8'
solve the problem for nonroot users, but the charset remains the same (it only displays as nonprivileged users UTF8, it is still Latin1).
And if (a big if) smnd could tell me WHERE should I use utf8mb4? Also in my.cnf file? I had my tables in utf8 and have migrated those with which I am working to utf8mb4 ...
Another Q: IS that applicable for Linux (Kubuntu) server:
https://www.youtube.com/watch?v=3M1Wpw4uOoM
Please help me, thanks, Gregor from lilaum.com
mysqli_set_charset('utf8').
init_connect is ignored for root connections.
utf8mb4 is effectively a superset of utf8. It is needed for Chinese and the new emoji, plus a scattering of obscure character sets.
PHP manual says:
MySQLnd always assumes the server default charset. This charset is sent during connection hand-shake/authentication, which mysqlnd will use.
MySQLnd is the MySQL native driver included with PHP 5.4 and above.
Unfortunately, I have to confirm that even in my system (PHP 5.6.17 with MySQL 5.5.47 on Debian Jessie 8.3) despite having configured /etc/mysql/my.cnf with the following entries
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8
the mysqlnd does not seem to assume the server default charset (utf8) but sets the connection charset to latin1 with collate latin1_swedish (maybe a default value considering MySQL AB was a swedish company).
So, it seems that there's no permanent way to set utf8 charset when connecting from a PHP application. You have to call
$mysqli->set_charset("utf8")
after each connection. This could be embedded in a custom 'dbconnect' PHP function in order to provide a sort of abstraction layer.

foreign character è is not saving in mysql

the name "Eugène" became "EugÃ?ne". Please, give me a solution. I tried before by changing db character set but, still not working.
Connection id: 2939
Current database: clcdb_final
Current user: root#localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.32-log MySQL Community Server (GPL) by Remi
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 45 min 59 sec
and table info: ENGINE=MyISAM AUTO_INCREMENT=57431 DEFAULT CHARSET=latin1
Just check mySql connector jar version. if you using back dated jar then this can be happen.
Verify that you have specified
"charset=utf8"
in your connection string.
As noted in Character Sets and Collations in General
MySQL can do:
Store strings using a variety of character sets
Compare strings using a variety of collations
Mix strings with different character sets or collations in the same server, the same database, or even the same table
Allow specification of character set and collation at any level
Verify that:
"charset=utf8"
And
Collation ==> utf8 - utf8_bin

UTF8 characters not showing correctly in Wordpress

I am running out of ideas - Wordpress is refusing to save UTF-8 encoded characters correctly:
http://www.letosanezkou.com/
you can see that when I edit the post content directly in the MySQl DB it works correctly. I have verified the mysql db:
mysql Ver 14.14 Distrib 5.5.24, for Linux (i686) using readline 5.1
Connection id: 2120
Current database: leto_wp1
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.24-cll MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
and my wp-config has the default UTF-8 lines:
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
When I try to update the post, that was edited in phpmyadmin it will save the post incorrectly.
Any ideas on how to fix this please?

Why am I getting unicode values back from SQLTables?

I'm trying to make a connection via ODBC from a Python program running on Ubuntu to a MySQL box on the same machine. (I'm using ODBC instead of DB-API because I'm going to be using different database engines and I want a consistent way of getting to the system catalog, like SQLTables.)
But when I connect to my MySQL database and run SQLTables, I get this for my first row:
(u'\U0067007a\U005f0061\U00690062\U006c006c\U006e0069\U005f0067\U00750061\U006f0074\U0061006d\U00690074\U006e006f\U0063005f\U00630063',
u'', u'\U00750061\U00680074\U0067005f\U006f0072\U00700075',
u'\U00410054\U004c0042', u'')
Clearly these are unicode values, but they look like they are for really high codepoints, and sure enough, I can't encode them into ASCII. All my table names should be ASCII.
Is there some setting that I'm missing or have wrong that is causing this?
my odbc.ini is:
[ODBC Data Sources]
mu = MySQL
[mu]
Description = MySQL Database Test
Driver = MySQL
Server = localhost
Database = ccc2
Port = 3306
My odbcinst.ini is
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/odbc/libmyodbc.so
FileUsage = 1
Found it. I needed to specify Charset=UTF8 in my connection paramters, like so:
[ODBC Data Sources]
mu = MySQL
[mu]
Description = MySQL Database Test
Driver = MySQL
Server = localhost
Database = ccc2
Port = 3306
Charset = UTF8