I want to use Cyrillic characters with my simple web app (flask with MySQL DB).
DB charset is set = cp1251 / collation = cp1251_general_ci
Charset/collation is specified during application connection to DB as follows:
application.config['SQLALCHEMY_DATABASE_URI'] = f'mysql+mysqlconnector://{creds["user"]}:{creds["pass"]}#{creds["host"]}:{creds["port"]}/{creds["dbname"]}?**charset=cp1251&collation=cp1251_general_ci**'
p.s. It's a small flask web app (pet project). Btw before I used Postgres with no problems (no bothering about charsets/collation). But I had to migrate to MySQL as Postgres is expensive to host # AWS RDS. So I migrated to MySQL # some free hosting.
When entering Latin characters it works / when entering Cyrillic letters it stores "????"
Cannot understand what's causing the problem. Thanks for your help!
Related
I am migrating a wordpress site from one server to another. I exported an sql dump from the old server and imported it into the new server database through phpmyadmin. But certain characters are not displayed correctly like the apostrophe and hyphen.
I figure this is because of the different database encoding present in the 2 servers. The old server has the character set encoding as utf8mb4_unicode_520_ci while the new server has the encoding latin1_swedish_ci.
I tried changing the "Character set of the file:" of the export dump by setting it to iso-8859-1 so that it would then get imported correctly into the latin1_swedish_ci but it gives an error during import of the SQL syntax.
How can I migrate the data here correctly?
Unless you have a specific reason to be using "latin1_swedish_ci" (and I can't imagine you do - it was the MySQL default at some point), you should not be using that at all. Change the character set encoding on the new server to match the former.
I have strange problem, meaning:
in my company we have 2 kinds of databases 1 oracle and 1 mysql and 1 remote in hosting.
when ERP which is on oracle codding is set to utf-8 is making update or insert to remote mysql db everything is ok all chars like ńłóść are coded correctly, but doing the same update to my local mysql db chars like ńłóść are replaced by ?. I tried to
change coding from utf8_general_ci to utf8_unicode_ci didn't work,
change engine from InnoDB to MylSam didn't work
varsion of my local MySQL is 5.6.12
version of my remote MYSQL is 5
but i don't think there is problem, i use wamp 2.4
Can i check in what encoding query is ?
Short answer: use utf8mb4. Search for it on Stack Overflow, or see How to support full Unicode in MySQL databases.
I'm using MySQL Workbench and successfully migrating a SQL Server database used with SilverStripe PHP CMS to MySQL on Linux. Problem is when the content is displayed on the Linux web server I have to change encoding to Western (Windows-1252) to get the content to display correctly. The site on Windows IIS with SQL Server displays correctly with the default UTF-8 encoding.
In the manual migration editing section on MySQL Workbench some columns say Collation Latin1_General_CI_AS migrated to utf8_general_ci so I gather this is correct.
The site is setting <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> in the HTML.
Migration process:
Use MySQL Workbeanch to migrate from SQL Server to MySQL on
production server
Export MySQL database on production server to *.sql file
Import *.sql file into Linux server using PHPMyAdmin and default UTF-8 encoding
I'm not sure where in the migration process I need to fix this?
This might not be about the migration process at all.
If you are using PHP to access the new database, the connection charset might be incorrect.
After setting up the connection you should set the connection charset to UTF-8.
$db = new MySQLi(HOST, USER, PASSWORD, DATABASE);
$db->set_charset('utf8');
Or, if you are not using MySQLi:
mysql_connect(/*...*/);
mysql_set_charset('utf8');
There are 3 possibilities of what could have gone wrong:
Encoding miss-configuration at the original SQL-server setup. Look at this post for more details on how this can happen: https://stackoverflow.com/a/20824533/684229. In this case, the encoding in the SQL-database is incorrect, but due to wrong setup it displays correctly.
You made a mistake in the migration process. Then the encoding in the new MySQL database is incorrect.
The encoding in the new MySQL database is correct, but there is an encoding miss-configuration at the new Linux MySQL setup, which makes it look incorrect.
To check which case applies, you have to check the encoding in both databases by some independent tool which for sure (200% at least!!!) has the encoding configured correctly. I would use PHPMyAdmin in case of Linux, I don't know what's available on SQL server. But make sure that this tool is configured correctly, otherwise you will get fooled!!!
Post the result and I will expand my answer accordingly.
EDIT: Dave, I have numbered the steps of your migration process. Please check the encoding of your MySQL database at two points - right after step 1 (before you do the export & import) as well as after you export & import in step 3. This will have to detect the exact point where it went wrong.
I've got a database that I want to export and import to another database on a different server, however after I've imported it I have character encoding issues i.e in some cases where there is a space in the html, a black diamond appears with a question mark inside.
I done the export a couple of months ago so can't remember if I simply imported the database via phpMyAdmin or used mysqldump! I'm going to re-import it today and wanted to know the best way to export and import. The HTML header on the website is utf-8, each database table has collation set to latin1_swedish_ci and the type is MyISAM.
The web server I am exporting from has the following settings:
MySQL charset: UTF-8 Unicode (utf8)
Apache/2.2.12 (Ubuntu)
MySQL client version: 5.1.37
PHP extension: mysqli
PhpMyAdmin Version information: 3.2.2.1deb1
The web server I am importing to has the following settings:
MySQL charset: UTF-8 Unicode (utf8)
Apache
MySQL client version: 5.5.24
PHP extension: mysqli
phpMyAdmin Version information: 3.4.10.1deb1
I would be grateful if someone can recommend the best way to export/import and if possible explain the reason behind the character encoding issues.
Thanks
I need to transfer my mysql DB from windows server to Ubuntu server.
So i made export in phpmyadmin on win and imported *.sql file in linux.
In linux PMA all looks okay, tables are healthy, no errors, and charter set is (cp1251), russian data in tables looks how it needed.
But when i try to run select in php script there is only "???????" in result, and echo mysql_client_encoding() showing that charset is latin1.
Please, tell me where is latin1 can be seted?
Thanks for help.
UPD: I am using now mysql_set_charset('cp1251'); after each db connection, but its not an pefect solution. Maybe someone can offer other idea?