Am developing a tamil website using ASP.NET MVC and MYSQL.
While updating the values (tamil language text) from ASP.NET MVC website to Database all my values as storing as format like this ??????????????
When I directly run the insert query into my database I am able to insert the tamil text into the database.
Asp.NET MVC : I have the below code
<meta charset="utf-8" />
MySQL - Create table syntax :
CREATE TABLE IF NOT EXISTS `Login` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`username` text COLLATE utf8_unicode_ci,
`password` mediumtext COLLATE utf8_unicode_ci,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
Note: I have been using the Entity Framework to connect with the MySQL database.
Is any thing missing from my side?
From Comment
Solution Found - just add ";Charset=utf8" to connection string.
Here is the working solution:
<add name="photostorageEntities"
connectionString="metadata=res://*/Models.Photos.csdl|
res://*/Models.Photos.ssdl|res://*/Models.Photos.msl;
provider=MySql.Data.MySqlClient;
provider connection string="server=ServerIP;
User Id=UID;password=PASS;
Persist Security Info=True;database=photostorage; Charset=utf8""
providerName="System.Data.EntityClient" />
Thanks everyone! :)
I also faced the exact same problem.
Add this connection property to the jdbc driver where you are defining the database connection.
<property name="connectionProperties" value="characterEncoding=UTF-8;characterSetResults=UTF-8"/>
I hope this will solve your problem.
Use following query to set the default character set to already created table
ALTER TABLE Login CONVERT TO CHARACTER SET utf8;
You are using collate in multiple places. The following will be enough
CREATE TABLE IF NOT EXISTS `Login` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`username` text,
`password` mediumtext,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
Related
I use MySQL 5.7, but I do not know how to config it to display Vietnamese correctly.
I have set
CREATE DATABASE brt
DEFAULT CHARACTER SET utf8 COLLATE utf8_vietnamese_ci;
After that I used "LOAD DATA LOCAL INFILE" to load data written by Vietnamese into the database.
But I often get a result with error in Vietnamese character display.
For the detailed codes and files, please check via my GitHub as the following link
https://github.com/fivermori/mysql
Please show me how to solve this. Thanks.
As #ysth suggests, using utf8mb4 will save you a world of trouble going forward. If you change your create statements to look like this, you should be good:
CREATE DATABASE `brt` DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
USE `brt`;
DROP TABLE IF EXISTS `fixedAssets`;
CREATE TABLE IF NOT EXISTS `fixedAssets` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`code` varchar(250) UNIQUE NOT NULL DEFAULT '',
`name` varchar(250) NOT NULL DEFAULT '',
`type` varchar(250) NOT NULL DEFAULT '',
`createdDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE INDEX `idx_fa_main` ON `fixedAssets` (`code`);
I've tested this using the data that you provided and get the expected query results:
name
----------------------------------------------------------------
Mould Terminal box cover BN90/112 612536030 39 tháng
Mould W2206-045-9911-VN #3 ( 43 tháng)
Mould Flange BN90/B5 614260271 ( 43 tháng)
Mould 151*1237PH04pC11 ( 10 năm)
Transfer 24221 - 2112 ( sửa chữa nhà xưởng Space T 07-2016 ) BR2
Using the utf8mb4 character set and utf8mb4_unicode_ci collation is usually one of the simpler ways to ensure that your database can correctly display everything from plain ASCII to modern emoji and everything in between.
I created a script using MySqlWorkbench, at the top of the script there is this:
CREATE SCHEMA IF NOT EXISTS `contacts` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
USE `contacts` ;
when I import this script in PhpMyAdmin, I get:
SQL query:
CREATE TABLE `contact` (
`id` int(11) NOT NULL,
`name` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
MySQL said: Documentation
1046 - No database selected
Why the schema contacts isn't creating a new database?
Use CREATE TABLE contacts.contact
(not allowed to comment yet, so forced to use answer.)
I am running into a bit of an issue.
You see I have made a WordPress website locally using WAMP and everything seemed to be working fine, until I tried to get the MySQL database imported onto the new live site where it gave an error:
"#1709 - Index column size is to large, The maximum column size is 767 bytes"
See image of the complete error here:
Now I have found some answers to what may be causing this here:
MySQL error: The maximum column size is 767 bytes
And here:
mysql change innodb_large_prefix
And although I understand what needs to be imlemented code wise, I am none the wiser as to where the code actually needs to be placed.
As aside from importing and exporting and editing the database credentials I never had to do anything else with MySQL, it is all a bit foreign to me.
And though I am more than happy to look more deeply into it at a later point in time, at this point I rather just want my live site to be working.
Well I figured it out, apparently I had to edit the SQL file itself and had to add ROW_FORMAT=DYNAMIC at the end of every CREATE TABLE Query which uses the INNODB engine.
So I changed this:
CREATE TABLE `xxx` (
`visit_id` bigint(20) NOT NULL AUTO_INCREMENT,
`visitor_cookie` mediumtext NOT NULL,
`user_id` bigint(20) NOT NULL,
`subscriber_id` bigint(20) NOT NULL,
`url` mediumtext NOT NULL,
`ip` tinytext NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`visit_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = #saved_cs_client */;
Into
CREATE TABLE `xxx` (
`visit_id` bigint(20) NOT NULL AUTO_INCREMENT,
`visitor_cookie` mediumtext NOT NULL,
`user_id` bigint(20) NOT NULL,
`subscriber_id` bigint(20) NOT NULL,
`url` mediumtext NOT NULL,
`ip` tinytext NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`visit_id`)
) ROW_FORMAT=DYNAMIC ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = #saved_cs_client */;
Then I re-imported the file onto the local server and then did a new export to the live server... and it is live now...finally.
I still find it a bit strange that mySQL doesn't automatically set rows to dynamic, once you exceed a certain amount of characters ( 747) and that it still works inside the existing database eventhough it shouldn't work...but maybe WAMP just has different environment settings vs the live server.
Anyway thanks all!
Error
SQL query:
CREATE TABLE `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_ci,
PRIMARY KEY (`meta_id`),
KEY `comment_id` (`comment_id`),
KEY `meta_key` (`meta_key`(191))
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
MySQL said: Documentation
#1050 - Table 'wp_commentmeta' already exists
I came across this issue and found that even if you drop the wp_commentmeta table, you are likely to have issues with other tables like wp_comments, wp_links etc.
Hence, the solution is just to drop the whole database, re-create a fresh one and restore to that. To do this, login to mysql:
mysql -u databaseuser -p
and then run the following command on your database:
drop database wordpress_database;
create database wordpress_database;
quit;
I had a similar issue and had to drop all the tables. Not recommended for the faint of heart. Make sure you have at least two different types of backups.
The error you are getting is pretty self explanatory!
You may think about executing the following SQL-Statement:
DROP TABLE wp_commentmeta;
I am inserting some non-ascii(specifically asian characters into mysql table column with charset utf8, but after insertion, if I retrieve it again, it shows up as ????. I checked the db, table and column charset, they are all utf8. what's wrong?
CREATE TABLE `test_utf` (
`test_id` bigint(20) NOT NULL auto_increment,
`raw_text` longtext,
PRIMARY KEY (`test_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into test_utf (raw_text) values('黄剑');
Problem solved!
I need to add characterEncoding=UTF-8 to whatever mysql client I'm using,
for example, when I use jdbc I need to specify "jdbc:mysql://localhost/dbname?characterEncoding=UTF-8" in connection url.