I am trying to set character sets to utf8mb4 and collation sets to utf8mb4_unicode_ci. On my website the emoji's looks fine when I get the data out of the table with php/mysql select. Only in phpMyAdmin (4.8.4) I see most emoji's as one questionamrk.
I try this:
Add to /etc/my.cnf:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Restart systemctl restart mariadb
I use on my website mysqli_set_charset($con, "utf8mb4");, <form accept-charset="UTF-8"> and <meta charset="utf-8">.
Result of SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%':
What am I doing wrong?
I use mysql version 5.5.60 (Mariadb).
Edit:
The problem might be phpmyadmin (4.8.4). It seems that phpMyAdmin is still using utf8. The global variabelen are set to utf8mb4 or utf8mb4_unicode_ci but I can't change the session variabelen:
I set in config.inc.php:
In the 'normal' table in phpMyAdmin:
And when I try SET NAMES everything looks fine:
Under General settings in phpMyAdmin the server connection collation is set on utf8_unicode_ci. I can select utf8mb4_unicode_ci, but then it switches back to utf8_unicode_ci :(
And on my website with select everything looks oké:
Related
I am creating a new server with the mysql_install_db tool. It sets the correct datadir, port, password, service etc. But My problem is that the charset and collation of my base tables are wrong. They need to be utf8mb4 and utf8mb4_general_ci.
I can't find a way to change these tables with the installation. When I change my.cnf/my.ini it only changes for newly created databases. But Since mysql_install_db creates the system databases, they are created wrong.
It also looks like my msyql_install_db.exe does not accept a defaults-file argument.
Something else is also weird. If I run the command to create a new database, it will also use utf8mb3 while I explicitly set the COLLATE to utf8mb4_unicode_ci.
CREATE DATABASE IF NOT EXISTS tt DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
I am using mariadb 10.6.4 which is the latest version.
Anyone knows how to setup the correct charset and collation to the system databases?
Tools\mariadb-winx64\bin\mysql_install_db.exe --datadir="Tools\mariadb-data" --password=PASSWORD --port=8137 --service=MyDB
[Update]
I tried to setup my.cnf with the following, but seems to take no effect: Change MySQL default character set to UTF-8 in my.cnf?
Also tried using a different way with initializing-insecure, but also the same results. I created a my.cnf with the correct encoding, but still got the wrong table encoding:
mariadb-winx64\bin\mariadbd.exe --defaults-file=./my.cnf --initialize-insecure --datadir=./Test
And my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
skip-grant-tables
port = 5137
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
We have a project where we're storing Facebook and Twitter posts in a Mysql database, as first almost all Emojis were being stored as ?. We've since gone ahead and made some configuration changes to the database server, and since then we're starting to see more Emojis saving and appearing correctly, however some Emojis are still showing as ?, sadly I'm not sure which ones they are. I know one of them was a basket ball.
When I execute the following commend on MySQL;
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%'
OR Variable_name LIKE 'collation%';
I see the following settings;
character_set_client = utf8
character_set_connection = utf8
character_set_database = utf8mb4
character_set_filesystem = binary
character_set_results = utf8
character_set_server = utf8mb4
character_set_system = utf8
collation_connection = utf8_general_ci
collation_database = utf8mb4_unicode_ci
collation_server = utf8mb4_unicode_ci
Our database server is hosted with Rackspace, we've asked them to set up the following configuration;
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
I've tested output from the database using a number of clients, PHP, Java and MySQL Workbench.
I'm at a loss now as to why some Emojis are not saving, and I've followed as much advice as I can find on the web.
character_set_client/connection/results = utf8 -- These three are changed by SET NAMES. What you list seems to be before SET NAMES is executed.
If you are connecting as root, init-connect is not executed; perhaps this is why you don't see it.
Establish a non-SUPER user for all application work; that way the init-connect will be executed.
I am using emojis in our project. our database had CHARACTER SET utf8. But emoji are not saved. The error is:
1366 Incorrect string value: '\xF0\x9F\x98\x9C\xF0\x9F...'
alert database, datatable CHARSET=utf8mb4, column CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci. Before that make sure mysql has a higher version than 5.5.3, you can use navicat to do that
modify the mysql configuration file, in windows it's my.ini, in linux it's my.cnf
[client] default-character-set = utf8mb4
[mysql] default-character-set = utf8mb4
[mysqld] character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
remove characterEncoding=utf-8 in property file
restart mysql server
I'd like every table and database (to be created) to be utf-8 that works with emojis. I understand that there are a few variables I need to define inside my.cnf:
init_connect='SET collation_connection = ??? '
init_connect='SET NAMES ???'
character-set-server = ???
collation-server = ???
However, I'm not sure what to put in the ???. What do I put inside my.cnf?
This article may help: https://mathiasbynens.be/notes/mysql-utf8mb4#utf8-to-utf8mb4
It explains in detail how to switch to utf8mb4 to support full unicode, thus allowing emojis using the following config:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
In addition to changing to utf8mb4 as #eol suggests, there may be more to do.
If you already have tables that have utf8 columns; do ALTER TABLE .. CONVERT TO CHARACTER SET utf8mb4.
When you connect, be sure to establish UTF-8 if the client has a non-mysql way of doing it, or use SET NAMES utf8mb4.
Keep in mind that root ignores init-connect. You should have a non-root 'user' for the application.
To support full Unicode in MySQL databases
For database: ALTER DATABASE DATABASE_NAME CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
For table:
ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
For column: ALTER TABLE TABLE_NAME CHANGE COLUMN_NAME COLUMN_NAME VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
It seems to me that phpMyAdmin imports tables by default with collation latin1_swedish_ci, how i change this?
In your Mysql configuration change the default-character-set operative under the [mysqld] tab. For example:
[mysqld]
default-character-set=utf8
Don't forget to restart your Mysql server afterwards for the changes to take effect.
For Linux:
You need to have access to the MySQL config file.
The location can vary from /etc/mysql/my.cnf to ~/my.cnf (user directory).
Add the following lines in the section [mysqld]:
collation_server = utf8_unicode_ci
character_set_server=utf8
Restart the server:
service mysqld restart
This is not a phpMyAdmin question.
Collations are part of recent MySQL releases, you must set the default collation of the server (or at least of the database) to change that behaviour.
To convert already imported tables to UTF-8 you can do (in PHP):
$dbname = 'my_databaseName';
mysql_connect('127.0.0.1', 'root', '');
mysql_query("ALTER DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
$res = mysql_query("SHOW TABLES FROM `$dbname`");
while($row = mysql_fetch_row($res)) {
$query = "ALTER TABLE {$dbname}.`{$row[0]}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
mysql_query($query);
$query = "ALTER TABLE {$dbname}.`{$row[0]}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
mysql_query($query);
}
echo 'all tables converted';
Code snippet taken from here.
For utf8mb4, add/change the following in the [mysqld] section:
collation_server = utf8mb4_unicode_ci
character_set_server = utf8mb4
Then restart the mysql service (for Ubuntu the command is sudo service mysql restart)
know this is an old post. But the way i changed the default charset through phpMyAdmin was:
phpMyadmin main page > Variables tab (Server variables and settings) > searched for "character" and changed all variables from "latin1" to "utf8".
(on a MAMP installation with phpMyAdmin v. 3.5.7)
And as the others said, this is the variables for MySQL and not some phpMyAdmin specific ones.
MySQL DB « change Collation Name of a Database|Table to utf8_general_ci inorder to support Unicode.
Change Configuration settings file also
XAMPP:
uncomment UTF 8 Settings from the Configuration settings file « D:\xampp\mysql\bin\my.ini
## UTF 8 Settings
#init-connect=\'SET NAMES utf8\'
collation_server=utf8_unicode_ci
character_set_server=utf8
skip-character-set-client-handshake
character_sets-dir="D:/xampp/mysql/share/charsets"
For MySQL server to support UTF8 and the below line of code in file my.cnf
## UTF 8 Settings
collation_server=utf8_unicode_ci
character_set_server=utf8
#see
XAMPP - Apache Virtual Host Setting
XAMPP security concept - Error 403,404
Insert this strings into my.ini (or my.cnf)
[mysqld]
collation_server = utf8_unicode_ci
character_set_server=utf8
Add into config.inc.php
$cfg['DefaultConnectionCollation'] = 'utf8_general_ci';
You need to restart MySQL server and remove cookies,data for domain where is located PhpMyAdmin
Reload page with PhpMyAmdin and at look the result
I wanted to use utf8mb4 instead, and the configuration had to be the following:
collation_server = utf8mb4_general_ci
character_set_server=utf8mb4
the server would not start if the character_set was set to utf8
The original question was for the default setting in phpMyAdmin.
I think the question relates to creating a NEW database in phpMyAdmin - when the page shows utf8mb4...
This IS a phpMyAdmin setting!
If you want the default for creating new databases to show utf8_general_ci.
Add the following 2 line to your config.inc.php file:
$cfg['DefaultCharset'] = 'utf8';
$cfg['DefaultConnectionCollation'] = 'utf8_general_ci';
See phpMyAdmin docs https://docs.phpmyadmin.net/en/latest/config.html and
https://docs.phpmyadmin.net/en/latest/config.html#cfg_DefaultConnectionCollation