【Mysql】character-set-server参数
分类: Linux
对于数据库级的字符集,如果没有办法重建数据库,可以在myf⽂件中使⽤character-set-server = utf8(要重启数据库服务),对于之前已经存在数据库,此参数不产⽣影响。如果之前的数据库A是latin1,在A中创建的表默认还是latin1,除⾮指定DEFAULT CHARSET!然⽽对于新建的数据库,则继承 myf⽂件中使⽤character-set-server = utf8!
[root@rac3 ~]# more /etc/myf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
character-set-server = utf8
关闭数据库服务,并重新启动!
[root@rac3 ~]# mysqladmin shutdown
[root@rac3 ~]# mysqld_safe &
[1] 15102
[root@rac3 ~]# Starting mysqld daemon with databases from /var/lib/mysql
[root@rac3 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql下载starting the servermysql> show variables like '%server%';
+----------------------+-----------------+
| Variable_name        | Value          |
+----------------------+-----------------+
| character_set_server | utf8            |
| collation_server    | utf8_general_ci |
| server_id            | 0              |
+----------------------+-----------------+
3 rows in set (0.00 sec)
--重新建⽴数据库,查看其默认字符集:为utf8
mysql> create database yql;
Query OK, 1 row affected (0.00 sec)
mysql> use yql;
Database changed
新建表的默认字符集和数据库的默认字符集⼀致!
mysql> create table t(id int);
Query OK, 0 rows affected (0.00 sec)
mysql> show create table t;
+-------+-------------------------------------------------------------------------------------+
| Table | Create Table                                                                        |
+-------+-------------------------------------------------------------------------------------+
| t    | CREATE TABLE `t` (
`id` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> show create database yql \G;
*************************** 1. row ***************************
Database: yql
Create Database: CREATE DATABASE `yql` /*!40100 DEFAULT CHARACTER SET utf8 */
1 row in set (0.00 sec)
ERROR:
No query specified

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。