Change MySQL-Charset from utf8 to utf8mb4 with PHPMyAdmin - mysqli

When I want to change MySQL-Charset from utf8 (utf8_general_ci) to utf8mb4 (utf8_unicode_ci) with PHPMyAdmin, it is sufficient when I do these things?
Change database collation to "utf8_unicode_ci"
Change tables collation to "utf8_unicodel_ci"
Change every text column to "utf8_unicodel_ci"
Change set_charset in my PHP code to "utf8mb4"
Is this correct or is something missing what to to? Where can occur any problems?

all coalition the same:
for database - utf8mb4_unicode_ci
table - utf8mb4_unicode_ci
columns - utf8mb4_unicode_ci
if You want avoid feature mistakes with string functions by mix coalition, good also set default coalition for server:
edit my.cnf (my.ini):
[mysqld]
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
because if You create new tables in feature not manual, but for from script - it create all new tables with default for server settings, and string function may stop work properly

Related

Create database defnition equivalent from mysql to postgresql

I need to migrate a mysql table to postgresql.
I need an accent and case insensitive database.
In mysql, my database has the next definition:
CREATE DATABASE gestan
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
How do I create an equivalent definition to postgresql?
I have read some posts, but it seems outdated.
create database getan
encoding = 'UTF-8';
There is no direct equivalent for the case insensitive collation _ci in Postgres.
You can define a new ICU collation that uses case insensitive comparison, but it can't be used as a default collation for a database, only for the collation on column level.
Related questions:
Install utf8 collation in PostgreSQL
https://dba.stackexchange.com/questions/183355
https://dba.stackexchange.com/a/256979

TYPO3 lists all tables in DB compare because of COLLATE

I'm using TYPO3 8.7.4 with PHP 7.0.22 and MariaDB 10.2.7.
The DB Compare inside the InstallTool shows me that TYPO3 wants to alter all tables because the current value differs from the expected by the collation of the table:
ALTER TABLE `be_groups` CHANGE `title` `title` VARCHAR(50) DEFAULT '' NOT NULL
Current value: title VARCHAR(50) DEFAULT '''' NOT NULL COLLATE utf8_general_ci
MariaDB implemented a change to the Information Schema COLUMNS table which is not backwards compatible with the output expected from the 'original' MySQL:
https://jira.mariadb.org/browse/MDEV-13132

MySQL to PostgreSQL table create conversion - charset and collation

I want to migrate from MySQL to PostgreSQL.My query for create table is like this.
CREATE TABLE IF NOT EXISTS conftype
(
CType char(1) NOT NULL,
RegEx varchar(300) default NULL,
ErrStr varchar(300) default NULL,
Min integer default NULL,
Max integer default NULL,
PRIMARY KEY (CType)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
What is the converted form of this query. I am confused with DEFAULT CHARSET=latin1 COLLATE=latin1_bin part. How can I convert this part?
That one would mean that the table uses only latin-1 (iso-8859-1) character set and latin-1 binary sorting order. In PostgreSQL the character set is database-wide, there is no option to set it on table level.
You could create a mostly compatible database with:
CREATE DATABASE databasenamegoeshere WITH ENCODING 'LATIN1' LC_COLLATE='C'
LC_CTYPE='C' TEMPLATE=template0;
However, I personally would consider a MySQL->PostgreSQL port also worthy of switching to UTF-8/Unicode.
The character set is defined when you create the database, you can't overwrite that per table in Postgres.
A non-standard collation can be defined only on column level in Postgres, not on table level. I think(!) that the equivalent to latin1_bin in MySQL would be the "C" collation in Postgres.
So if you do need a different collation, you need something like this
RegEx varchar(300) default NULL collate "C",
ErrStr varchar(300) default NULL collate "C",
min and max are reserved wordds in SQL and you shouldn't use them as column names (although using them as column names will work I strongly suggest you find different names to avoid problems in the future)

restore the database to a different collation

I tried to find how do I restore the database to a different collation.
For example:
Server collation is Czech_CI_AS
Database, which I backed up, has a collation Czech_CI_AS.
And I need to restore a backup of the database, but with the
collation SQL_Latin1_General_CP437_CI_AI.
Somewhere I'm doing something wrong, will you help me?
As you've discovered, the collation of the original database is preserved in the backup, and so when you create a new database from this backup somewhere else, the original collation comes with it. There is no option on the restore command to change collation during the restore.
You could ALTER DATABASE to a different collation after you have restored the database, but note that this will not change the collation of all the existing objects in the database, you will need to alter the collation of columns in individual tables yourself.
See MSDN:
When you change the database collation, you change the following:
Any char, varchar, text, nchar, nvarchar, or ntext columns in system tables are changed to the new collation.
All existing char, varchar, text, nchar, nvarchar, or ntext parameters and scalar return values for stored procedures and
user-defined functions are changed to the new collation.
The char, varchar, text, nchar, nvarchar, or ntext system data types, and all user-defined data types based on these system data
types, are changed to the new default collation.
You can change the collation of any new objects that are created in a
user database by using the COLLATE clause of the ALTER DATABASE
statement. This statement does not change the collation of the columns
in any existing user-defined tables. These can be changed by using the
COLLATE clause of ALTER TABLE.

how can i change the "character type" of a database in postgresql?

I'm using postgreSQL 9.1
I've set the Collation and the Character Type of the database to Greek_Greece.1253 and I want to change it to utf8
To change the collation I should use this, right?
But how can I change the character type?
Thanks
EDIT
I ment to wright C instead of utf8. I would like to change the Collation and the Character Type to C
You cannot change default collation of an existing database. You need to CREATE DATABASE with the collation you need and then dump/restore your schema and data into it.
If you do not want to recreate the database - you can specify collation for every text collumn in your db.
Here is detailed postgres manual on collations: Collation Support.
First line of this manual page states:
LC_COLLATE and LC_CTYPE settings of a database cannot be changed after
its creation.
CREATE DATABASE, pg_dump, pg_restore