Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swedish characters in UTF8 (MySQL5)

Status
Not open for further replies.

mrdance

Programmer
Apr 17, 2001
308
SE
I'm trying to insert swedish characters through the MySQL Connector (using VB.NET). The string looks ok before inserting but for example does the swedish character "ä" look like "ä" in the database.

Why is that, do I have to set any encoding or something when inserting?

--- neteject.com - Internet Solutions ---
 
I use the default encoding "latin1", and characters like 'ä' are inserted correctly into the database. However there could be a problem rendering characters like that, depending on the client program. I notice that in the "mysql" command-line client, 'ä' is not rendered correctly, but it is rendered correctly in GUI clients.

So, problem is probably not in the insertion code or the database, but in the rendering. What client program are you having problems with?
 
EMS MySQL Manager, I'm using version 2.8.7.3, maybe to old?

--- neteject.com - Internet Solutions ---
 
You could try one of the clients available from the MySQL website; I use MySQL Control Centre, which works fine.
 
I tried the latest one of MySQL Control Center but it displayed the same "wrong" characters.

What is default encoding anyway? On installation I set it to UTF8 somewhere. I need to have that in order to be able to insert japanese or chinsese characters in the future.

So if it's not the client, do I have to convert the strings in anyway before inserting (they "look" ok before inserting)

--- neteject.com - Internet Solutions ---
 
You can check what character set (encoding) each field uses, and the default used when none is specified, by doing:[tt]
SHOW CREATE TABLE tablename[/tt]
If that's not right, you can then do (for each required field):[tt]
ALTER TABLE tablename
MODIFY fieldname CHAR(50) CHARACTER SET 'utf8'[/tt]
as well as:[tt]
ALTER TABLE tablename CHARACTER SET 'utf8'[/tt]
to set the default for new fields in the table.
You could also set the default for new tables:[tt]
ALTER DATABASE dbname CHARACTER SET 'utf8'[/tt]

I don't think non-ASCII strings need any special conversion, except for the usual escaping of special characters like quotes and backslashes.
 
It says:

DROP TABLE IF EXISTS babeltool_words;
CREATE TABLE `babeltool_words` (
`id` bigint(20) NOT NULL auto_increment,
`tag_id` bigint(20) NOT NULL default '0',
`language_id` mediumint(9) NOT NULL default '0',
`words` char(50) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `tag_lang` (`tag_id`,`language_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

But one very strange things. All of the MySQL Gui editors I have won't let me insert rows with letters å,ä or ö?! If I try to write in a row of the GUI or using INSERT the content just get empty when selecting the row?! I used MySQL Control Center. Why is this happening?

--- neteject.com - Internet Solutions ---
 
That's strange.

I have a table as follows:[tt]
CREATE TABLE `t` (
`s` char(10) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
[/tt]
When I do:[tt]
INSERT t VALUES ('å,ä or ö')[/tt]
followed by:[tt]
SELECT * FROM t[/tt]
I get:[tt]
å,ä or ö[/tt]

I've no idea what could be happening at your end.
 
Just wanted to sum this up. I had 2 problems:

1. Character "ä" looked like "ä" when deliverad by .NET dataprovider.

Solution: I used CHARSET=utf8 in the connection string AND used MySQL Query Browser instead.

2. When editing a row manually with with both EMS Manager and MySQL control centre. When insering an "ä" it just became a blank row.

Solution: I used MySQL Query Browser instead.

Thanks TonyGroves for your time!

--- neteject.com - Internet Solutions ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top