问题
It seems to me that phpMyAdmin imports tables by default with collation latin1_swedish_ci, how i change this?
回答1:
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.
回答2:
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
回答3:
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.
回答4:
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.
回答5:
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
)
回答6:
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
回答7:
- Insert this strings into
my.ini
(ormy.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
回答8:
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
来源:https://stackoverflow.com/questions/153706/change-default-collation-in-phpmyadmin