Datas from mysql database don't display on website - mysql

I started my Project with UTF8 Database for the development. At the time of project completion, my Professor gave me the database of type Latin1. Because of Type Conflicting my project is not working properly, result my server side code doesn't access the database.
I tried much conversion: My Professors database into UTF8, but it failed.
Still I’m facing the issue. Kindly assist me in this regards.
Thank you !

You may try a charset converter like MySQL charset converter
This PHP script can be used to convert your MySQL database tables from latin1-to-UTF8 while retaining the integrity of all internal multibyte characters.

You could try this:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;
replace charset_name with latin1
You can also change columns individually
ALTER TABLE TableName MODIFY ColumnName ColumnType CHARACTER SET latin1;

Related

Strange character appearing in MySQL database field

I've imported some data from an old FileMaker program into a mysql database and I've noticed some strange characters. What is the best way to get rid of all these?
It seems the data you imported into your MySQL DB has a different character set (Collation) then what you set when you built the table in MySQL.
My guess would be those "strange characters" are an emoji. Which for example in utf8 charset, aren't defined. But utf8mb4 they would be.
The short answer is, find what charset the data was originally made in, and build your new data table with the same charset.
MySQL Workbench
The Charset can be manipulated easily in MySQL Workbench by right clicking the schema then table in question, click on the wrench.
SQL Syntax
Or via something similar to :
ALTER TABLE YourTableName CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE YourTableName modify name text charset utf8mb4;
I believe your varchar length are overflowing.
For example: field varchar(10) and you put "STRING OVER 10 CHARACTERS" this may cause trash on String.

How to convert mysql latin1 to utf8

I inherited a web system that I need to develop further.
The system seems to be created by someone who read two chapters of a PHP tutorial and thought he could code...
So... the webpage itself is in UTF8 and displays and inputs everything in it. The database tables have been created with UTF8 character set. But, in the config, there is "SET NAMES LATIN1". In other words, UTF8 encoded strings are populated into the database with forced latin1 coding.
Is there a way to convert this mess to actually store in utf8 and get rid of latin1?
I tried this, but since the database table is set to utf8, this does not work. Also tried this one without success.
I maybe able to do this by reading all tables in PHP with latin1 encoding then write them back to a new database in utf8, but I want to avoid it if possible.
I managed to solve it by running updates on text fields like this:
UPDATE table SET title = CONVERT(CONVERT(CONVERT(title USING latin1) USING binary) USING UTF8)
The situation isn't as bad as you think it is, unless you already have lots of non-Roman characters (that is, characters that aren't representable in Latin-1) in your database already. Latin-1 is a proper subset of utf8. Your web app works in utf8 and your tables' contents are in utf8 as well. So there's no need to convert the tables.
So, try changing the SET NAMES latin1 to SET NAMES utf8. It will probably solve your problem, by allowing your php program's connection to work with the same character set as the code on either end of the connection.
Read this. http://dev.mysql.com/doc/refman/5.7/en/charset-connection.html
Change column data type
to VARBINARY
and it's automatically convert the latin1 datas
Thank you guys.
I hope it's helpful.

How to store other languages in mysql database using ruby?

I want to store languages other than English in MySQL database using Ruby. I've tried to store Hindi language characters in MySQL database, but got ActiveRecord::StatementInvalid error. Here is the attached screenshot -
Please help me solve this problem. Thanks in advance.
You could run the following command on your desired table(s):
ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MySQL docs on collation and character set configuration.
Hope it helps!

best solution for Mysql error in rails 4 app 'Incorrect string value'?

I have a rails application, in which I am using ‘delayed_job_active_record’ gem for running background jobs. While using the method ‘.delay’ with an object, I am getting the following mysql error:
**
‘Incorrect string value: '\xE2\x9C\x93"\x0A ...' for column 'handler'
at row 1
**
I already searched for the above error and found that its because of the difference in encoding in mysql and rails. The solution suggested by many programmers is to alter the encoding in mysql database to utf8.
But I also read that MySQL’s utf8 charset only partially implements proper UTF-8 encoding. It can only store UTF-8-encoded symbols that consist of one to three bytes; encoded symbols that take up four bytes aren’t supported. Which might cause trouble in some other cases. Also, when I tried to insert the value directly in mysql, it worked like a charm. Suggesting that the issue might lie elsewhere.
So, can anyone please suggest the right method to rectify this problem?
Today, I found a fixed a very similar bug.
You say:
when I tried to insert the value directly in mysql, it worked like a charm
... it's not clear whether you're inserting the value into the model, or into the DelayedJob#handler column?
In my case, the problem was, certain columns in my (old, legacy) database had DEFAULT CHARSET=latin1 ... so, I needed to manually convert them to UTF8.
Specifically, the model that .delay was being called upon was UTF8, but the delayed_jobs table was latin1. So it was only when the app serialized the UTF8 model and attempted to insert it into the latin1 handler column of the delayed_jobs table, that the exception was raised. It's a little tricky.
Here is the core of the migration I wrote to convert the rando-latin1 tables to utf8:
%w( table1
table2
table3 ).each do |latin1_table_with_char_columns|
execute("ALTER TABLE #{latin1_table_with_char_columns} CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;")
end
Here is a good, related StackOverflow post which is more generally about converting db columns to UTF8: How to convert an entire MySQL database characterset and collation to UTF-8?
Best of luck!

Converting data from LATIN1 to UTF8 in MySQL

I'm trying migrate a MSSQL database to MySQL. Using MySQL Workbench I moved the schema and data over but having problems converting the character encoding. During the migration I had the tool put text into BLOBS when there was problems with the encoding.
I believe I've confirmed that the data that is now in MySQL is *latin1_swedish_ci*. To simplify the problem I'm looking at ® symbols in one of the columns.
I wanted to convert the BLOBS to VARCHAR or TEXT with UTF8 encoding. I'm running this SQL command on one of the columns:
ALTER TABLEbookdetailsMODIFYBookNameVARCHAR(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Instead of converting the ® it is just removing them which is not what I want. What am I doing wrong? Not that reading half the internet trying to find a solution isn't fun but 3 days in and I think my eyes are about to give out.
MySQL workbench has a UI that is relatively simple to nav. If you need to change the collation of the tables or schemas, you can right click them on the Object Browser and go to alter table, or alter schema there you can change the data types, and set the collation to whatever you want.