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
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
I'm trying to set the default-default characterset for a new created mysql database. Because I'm lazy, I will use "CREATE DATABASE blahblah;" without providing additional "CHARSET" or "DEFAULT COLLATE". After "SHOW CREATE DATABASE blahblah;" I see:
blahblah | CREATE DATABASE `blahblah` /*!40100 DEFAULT CHARACTER SET latin1 */
Latin1? I need utf8. Let's change my.cnf and mysqld.cnf.
mysqld.conf (server config) is
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
.my.cnf (my local file) is
[client]
default-character-set=utf8
Just to by sure, let's restart the server, drop the database, create and... again latin1.
To be honest, I also tried character_set_server (underscores, instead of dashes), copy the entries to .my.conf back and forth... and there is still the f***g latin1.
So... did I made a typo? Do I miss any extra line somewhere? Is it impossible to set a default-default charset, so I need to provide them everytime I do a "create database..."?
Ubuntu 18.04.2, mysqld 5.7.26-0ubuntu0.18.04.1
(I am aware of the Change default collation/character set, but it doesnt work)
I updated MySQL to latest version 8.0.11 yesterday and tried to use RMySQL to connect to MySQL, but it was not working and I could not find any solution.
My code:
library(RMySQL)
con <- dbConnect(MySQL(), user="hello", password="hi", dbname = "webscrape", host="xx.xxx.xxx.xxx", port=xxxx)
Error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't initialize character set unknown (path: compiled_in)
I solved this problem like this:
User Windows
1.Error in .local(drv, ...) :
Failed to connect to database: Error: Can't initialize character set unknown (path: compiled_in)
After adding these lines:
file path: %PROGRAMDATA%\MySQL\MySQL Server X.X\my.ini
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
skip-character-set-client-handshake
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
2- Authentication plugin 'caching_sha2_password' cannot be loaded
ALTER USER 'yourusername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'youpassword';
References:
MySQL my.ini location
Change MySQL default character set to UTF-8 in my.cnf?
Authentication plugin 'caching_sha2_password' cannot be loaded
Had the same problem. Tried changing character sets on the schema. Also tried reinstalling MySQL with the legacy authentication method option and still no luck with RMySQL.
Tried RMariaDB package and it worked. I would switch to RMariaDB rather than downgrading MySQL.
https://cran.r-project.org/web/packages/RMariaDB/
I had this problem as well and I noticed in MySQL 5.8, which was released recently, the default character set of the server and client connections have now been set to utf8mb4 by default. With MySQL 5.7 the default character set was set to utf8.
I tried playing around with the character sets of the server and and client, reverting the values to utf8 but I just couldn't get it to work so I reverted my installed MySql to 5.7.
RMySQL worked then after.
It feels like RMySQL cannot support utf8mb4 at the moment and needs to be updated.
Related to this problem, one solution that would prevent you from changing your R preferred library and/or downgrading MySQL can be found at this post.
You just need to change your my.cnf settings.
I have the same Pb :
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't initialize character set unknown (path: compiled_in)
I try the solution of Hugo (modify the my.ini), David Guerin (using RMariaDB) but both are not working. After some research and experience this solution is working for me
Modify my.ini (this is the path to find C:\ProgramData\MySQL\MySQL Server 8.0) :
By opposit to the answer of Hugo, you need to put utf8mb4 (utf8 is not the good one)
[client]
default-character-set = utf8 (the old line "utf" to "utfmb4")
default-character-set = utf8mb4 (the new line with modification)
[mysql]
default-character-set = utf8 (the old line "utf" to "utfmb4")
default-character-set = utf8mb4 (the new line with modification)
[mysqld]
character-set-client-handshake = FALSE (new line to add)
character-set-server = utf8mb4 (the old line "utf" to "utfmb4")
collation-server = utf8mb4_unicode_ci (new line to add)
skip-character-set-client-handshake (Line to remove)
In mysql, you need to change your password :
ALTER USER root#localhost IDENTIFIED WITH mysql_native_password BY 'mot-passe';
I habe install rails and everything else needs onto a new CentOS 7 server. I have create mysql database via command line and then I've edited it to use character set utf8 and collation utf8_general_ci.
Rails worked.
Then I configured /etc/my.cnf to include some default settings for charset and collation:
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
init_connect=‘SET collation_connection = utf8_general_ci’
[client]
default-character-set = utf8
Rails stopped working saying it can't connect to the mysql.
Obviously, I could reconfigure something in Rails to solve this, but I don't know what.
Thanks for the help.
In my.cnf, use only apostrophe ' or double quote ", not ‘ and ’.
In order to use 4-byte utf8mb4 in MySQL (5.6.11), I have set the following variables in the my.ini file (my.cnf is not found). This file is located in a hidden folder named Application Data (C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6) on Windows XP. It is not available under the installation directory.
[client]
port=3306
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
init-connect='SET NAMES utf8mb4'
collation_server=utf8mb4_unicode_ci
character_set_server=utf8mb4
And then issuing the following command,
SHOW VARIABLES
WHERE Variable_name
LIKE 'character\_set\_%'
OR Variable_name LIKE 'collation%';
still displays the following list.
From the picture itself, it is clear that several variables are still using 3-byte utf8.
Before doing this, the following command had already been issued to make corresponding changes to the database itself.
ALTER DATABASE database_name
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
And the following command had also been issued on each and every table in the said database.
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
Nevertheless, what is the reason why some variables have not yet been set to the said character set as well as the collation? What is missing?
The system (operating system) itself was restarted after every single task specified above had been carried out.
The client usually sets these values when connecting. The settings in my.ini are merely defaults which apply when the client does not explicitly specify a connection encoding. Since they're unreliable, every client should specify a connection encoding. Since you've got some fancy screenshot there I'll guess that you're connecting with some GUI utility which probably explicitly does set some connection encodings.
PHP example of setting a connection charset:
new PDO('mysql:host=localhost;charset=utf8mb4')
If you show your global variables, you might see that all your settings are correct actually.
SHOW GLOBAL VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
This might be related to this bug
I also faced the same problem in the past. I changed a DB charset from utf8 to utf8mb4. Executing queries directly from mysql command line was ok but I had problem inserting emojis with Workbench. I ended up setting it manually by running
SET NAMES 'utf8mb4'
every time I open a connection to my DB with Workbench.
Using Sequel Pro as alternative was fine as well.
I think you are connecting as root, hence the init-connect='SET NAMES utf8mb4' is not executed.
It is unwise to use root (or SUPER) for any application code; just for administrative actions.
On win7
use "win + R" and type "services.msc"
find service of mysql
check the file path. It will tell you where the my.ini
open and add some properties:
[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 the mysql service