special characters in mysql - mysql

I have a mysql DB contains arabic data. when opening the db via mysql workbench the data looks like "ßÇÙã ÇáÌãÇÓí".
when making a simple php file that read from the DB the data looks fine(arabic).
but when reading the data via ASP.net the data looks like "ßÇÙã ÇáÌãÇÓí".
Please help me.

Before running SELECT query from your ASP.net application try running two queries after you connect to the database:
SET CHARACTER SET 'utf8';
SET NAMES utf8;
Basically you need to make your app aware of possible international characters.
P.S. This should be run again every time connection is established, e.g. you can't run it once from MySQL workbench and fix your app. Your app need to do that on its own.

Related

MySQL Workbench Migration: MSSQL to MySQL - Incorrect String Value

I have a .NET 6 application that is currently backed by MSSQL database, that is maintained by Entity Framework using a Model First approach. I am trying to migrate it to use a MySQL database backend, for a variety of reasons.
I have installed MySQL Locally (Windows) to start exploring and getting it working. I can migrate the schema easily enough (With either MySQL Workbench or using EF) but migrating the data is proving to be a little tricky.
Around half of the tables migrated fine, but the other half, relating to string data, are failing due to errors which look a little like this - the column obviously differs from table to table. The source data is nvarchar in SQL, and the destination is type `varchar'
Statement execution failed: Incorrect string value: '\xF0\x9F\x8E\xB1' for column 'AwayNote'
Does anyone know how I can get the Migration to run successfully?
The research I have read has said to ensure server and table character sets are aligned as per the below.
I have set up my Source as SQL using the ODBC FreeTDS
The data import screen is set up like this - the check box doesn;t seem to affect things especially.
I have MySQL setup with this too, which I have also read is important.
[mysql]
default-character-set = utf8mb4

Ruby - mysql2 driver changing encoding / various utf-8 issues

I have an API running on Sinatra. It queries a mysql databases, and returns data in json or xml format. I'm having a problem with unicode data. If I query the production database from the console, I'll get data correctly:
persönlichen
However, in my API results (or if I were to query the database in irb using the mysql2 gem), I get this:
persönlichen
Everything works swimmingly on my development box, which is confounding my efforts to solve the problem.
I have done everything I can to make sure that the database is utf-8 only (encodings, collations, client and server character sets are all utf-8). I'm using the mysql2 driver, which supposedly forces everything to utf-8. I'm setting :encoding => 'UTF8' on my active record connection.
What am I missing?
I was able to nail the problem down - the data wasn't encoded correctly in the database. I was populating my database using a sql dump file - I added this to the top, and everything worked great:
set names utf8;
create database if not exists `my_db_name` CHARACTER SET utf8 COLLATE utf8_general_ci;

mysql wrong connection encoding

I have mysql tables with utf8 encoding. The Data Backend and phpmyadmin are also set to utf8.
But something went wrong and i was told the connection was set wrong. It is easy to fix, but the Problem is, that now the whole Database is in the wrong enconding and if i fix the connection, the wrong data will be displayed in the Backend. What would be the simplest way to "convert" all fields of all tables? I would have written a script that runs over all tables and fields with something like utf8_decode/encode, but I would like to know if there is a nicer way?
If you have, for example, é instead of é in your DB, you could do the following
Export using mysqldump
Run a PHP script doing utf8_encode(file_get_contents('dump_file.sql')) and output it to a correctly encoded dump file
Import that new file using mysql
I guess that there could be smarter ways but I hope this will help.

Select * from Database 1 and insert into database 2

I have 2 Database in my VB.net application. I am using 1st database for daily operations. I would like to send one of the table records to online database. How Can I do that? First database is MSSQL Online database is MYSQL. I have created connections already using MYSQL .net connector.
Any Help will be appreciated.
Regards
Have a look at using a Linked Server instance on SQL Server to write the data to MySQL using the four name notation.
SQL SERVER – Explanation and Example Four Part Name
SQL Server Four-part naming
Ok here is a rough set of steps you need to follow
Query the MSSQL database and retrieve the data you want. Storing it in a DataTable may be the best option starting off.
Loop through the DataTable rows and build an INSERT statement that will be run against the MYSQL database.
Execute the command against the MYSQL db.
This is the basics of what you need to do to get a simple working system. Also take a look at Transactions as a way to manage the rollback of data when something goes wrong.
I'm assuming this is a research project If you are planning on using this code in a production system then i would look into a different alternative such as uploading data files to a service attached to the MYSQL database. This would allow you to batch and retry an import when something goes wrong.

Managing Unicode Data in MySQL and VB.NET

I wish to develop a client-server application in VB.NET. I want to store some fields in
Unicode. As per MySQL documentation I tried the fields with varchar and charset UTF-8 for storing Unicode data.
I could insert data using the MySQL connector command object but when I try to display data in datagridview some junk is appearing.
What am I missing?
I don't know VB.NET, but you should have the possibility to set the encoding of the database connection from your application to MySQL when setting up to connection. Is that part set to UTF-8 as well?
Alternatively you can try issuing the following MySQL command after you connect:
SET NAMES utf8