0 0

linux 下在终端中直接网mysql 插入中文出错,这是我的my.cnf 文件和字符编码显示结果.5

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set=utf8

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
character-set-server=utf8
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size         = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

[mysqldump]
quick
quote-names
max_allowed_packet = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
default-character-set=utf8
[isamchk]
key_buffer = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/





mysql> SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)








2014年7月24日 11:45

2个答案 按时间排序 按投票排序

0 0

在终端执行以下命令:
tee /etc/mysql/conf.d/utf8_charset.cnf 1>/dev/null <<MYSQL_CONFIG
[mysqld]
character_set_server = utf8
collation_server = utf8_general_ci
max_allowed_packet=64M
MYSQL_CONFIG

mysql -e "SET GLOBAL character_set_server=utf8;"
mysql -e "SET GLOBAL collation_server=utf8_general_ci;"

2014年7月25日 12:27
0 0

那就采用命令行的方式来修改,分别修改server、database、table默认的字符集

引用
mysql> use callcenter; 
Reading table information for completion of table and column names 
You can turn off this feature to get a quicker startup with -A 
 
Database changed 
 
mysql> alter database callcenter character set utf8; 
Query OK, 1 row affected (0.00 sec) 
 
mysql> set names 'utf8'; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> use callcenter; 
Database changed 
mysql> select * from um_group; 
+----+------+----------------+------+ 
| id | name | description    | type | 
+----+------+----------------+------+ 
|  1 | ??   | ?????????????  |    2 | 
|  2 | ???  | ?????????????? |    2 | 
|  3 | aaaa | aaaaaa         |    2 | 
|  3 | ??   | ??             |    2 | 
|  4 | ??   | ??             |    2 | 
|  5 | ??   | ??             |    2 | 
+----+------+----------------+------+ 
6 rows in set (0.00 sec) 
 
mysql> select * from test; 
+----+------+-------------+------+ 
| id | name | description | type | 
+----+------+-------------+------+ 
|  5 | ??   | ??          |    2 | 
+----+------+-------------+------+ 
1 row in set (0.00 sec) 
 
mysql> show variables like 'character_%'; 
+--------------------------+----------------------------+ 
| Variable_name            | Value                      | 
+--------------------------+----------------------------+ 
| character_set_client     | utf8                       | 
| character_set_connection | utf8                       | 
| character_set_database   | utf8                       | 
| character_set_filesystem | binary                     | 
| character_set_results    | utf8                       | 
| character_set_server     | latin1                     | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+ 
8 rows in set (0.00 sec) 
 
mysql> set character_set_server=utf8; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> select * from test; 
+----+------+-------------+------+ 
| id | name | description | type | 
+----+------+-------------+------+ 
|  5 | ??   | ??          |    2 | 
|  6 | ??   | ??          |    2 | 
+----+------+-------------+------+ 
2 rows in set (0.00 sec) 
 
mysql> drop table test; 
Query OK, 0 rows affected (0.04 sec) 
 
mysql> create table test( 
    -> name varchar(20) 
    -> ); 
Query OK, 0 rows affected (0.04 sec) 
 
mysql> insert into test values('啊啊啊'); 
Query OK, 1 row affected (0.00 sec) 
 
mysql> select * from test; 
+-----------+ 
| name      | 
+-----------+ 
| 啊啊啊 | 
+-----------+ 
1 row in set (0.00 sec) 

2014年7月24日 12:51

相关推荐

    MySQL各版本my.cnf配置文件.rar

    在这个名为"MySQL各版本my.cnf配置文件.rar"的压缩包中,包含了适用于MySQL 5.6、5.7和8.0这三个主要版本的my.cnf配置文件,这些文件已经过优化,可以有效提升MySQL数据库的并发处理能力。 首先,我们来了解一下my....

    修改my.cnf之后启动mysql出错(完美解决).docx

    my.cnf 文件通常位于 /etc/mysql/ 目录下。 MySQL 启动错误的原因 MySQL 启动错误可能是由于多种原因引起的,例如: 1. 配置文件 my.cnf 的修改不当,导致 MySQL 服务器无法正确启动。 2. MySQL 服务器的进程 ID ...

    linux下mysql my.cnf 文件

    linux下mysql my.cnf 文件已经配置好 路径根据实际情况自己修改linux下mysql my.cnf 文件已经配置好 路径根据实际情况自己修改linux下mysql my.cnf 文件已经配置好 路径根据实际情况自己修改

    linux下mysql配置文件my.cnf详解.pdf

    在Linux环境中,MySQL的主要配置文件是`my.cnf`,它是数据库服务器启动时读取的配置文件,用于设定各种参数和选项,以优化数据库的性能、安全性以及资源使用。这份文档将深入探讨`my.cnf`的结构、主要配置项及其作用...

    MySQL 8.0.35 版本 my.cnf文件

    MySQL 8.0.35 版本 my.cnf文件

    MySQL中配置文件my.cnf因权限问题导致无法启动的解决方法

    本文主要给大家介绍了关于MySQL中配置文件my.cnf因权限问题导致无法启动的相关解决过程,分享出来供大家参考学习,下面来一起看看详细的介绍: 问题描述 MySQL 无法启动,报如下错误: 问题分析 查看 MySQL 错误...

    CentOS7下MySQL8的主主互备安装文档和my.cnf配置文件

    首先,我们从【标题】入手,"CentOS7下MySQL8的主主互备安装文档"意味着我们将学习在CentOS7这个Linux发行版上安装MySQL 8.0数据库服务器,并设置主主复制(也称为主备同步),使得两个或多个MySQL实例可以相互备份...

    mysql-5.7.24的my.cnf

    mysql-5.7.24的my.cnf。适用于生产环境。相关配置已经写好,直接可以用。 mysql-5.7.24的my.cnf。适用于生产环境。相关配置已经写好,直接可以用。 mysql-5.7.24的my.cnf。适用于生产环境。相关配置已经写好,直接...

    Linux MySQL基础配置文件my.cnf

    Linux环境, 通过编辑my.cnf文件,设置MySQL数据库字符集,centos6.5 安装MySQL 5.7.21 ,没有找到my.cnf文件,此文件为基础配置文件

    mysql配置文件my.cnf

    MySQL是世界上最受欢迎的关系型数据库管理系统之一,而`my.cnf`是MySQL服务器的主要配置文件,它定义了数据库的运行参数和服务行为。这个文件对于优化性能、确保安全性以及满足特定的系统需求至关重要。以下是对`my....

    linux下mysql配置文件my.cnf详解

    Mysql 配置文件 my.cnf 是 Mysql 数据库服务器的核心配置文件,在 Linux 下 plays a crucial role in configuring Mysql 服务器的行为。该文件中包含了多个配置选项,这些选项可以控制 Mysql 服务器的各种方面,例如...

    MySQL中my.cnf文件选项

    `my.cnf`文件是MySQL服务端的核心配置文件之一,它通常位于系统的特定目录下(例如Linux系统中通常位于`/etc/mysql/my.cnf`或`/etc/my.cnf`)。此文件包含一系列的配置选项,这些选项决定了MySQL服务器的行为特性。...

    MySQL 8.0 的详细 配置 my.cnf

    MySQL 教程 MySQL 是最流行的关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System:关系数据库 MySQL8.0数据库的一般配置 Linux环境的配置文件

    mysql linux 下配置my.cnf

    mysql linux 下配置my.cnfmysql linux 下配置my.cnfmysql linux 下配置my.cnf

    mysql5.7 my.cnf配置文件优化

    mysql5.7优化后的配置文件,mysql5.7主从架构配置环境,生产环境直接使用,推荐生产环境5.7版本使用最稳定版本5.7.21。

    Linux上安装mysql的配置文件(my.cnf)

    Linux上安装mysql的配置文件(my.cnf)

    ubuntu mysql my.cnf 服务器最佳配置

    ubuntu mysql my.cnf 服务器最佳配置(16G,32G 内存)

    MySQL my.cnf配置文件完美详解

    ### MySQL my.cnf配置文件详解 #### 概述 `my.cnf` 是 MySQL 数据库管理系统的核心配置文件之一,用于定义 MySQL 各个组件的工作参数。通过对 `my.cnf` 文件的理解与设置,可以实现对 MySQL 服务的有效管理和优化...

    【荐】mysql服务性能优化—my.cnf_my.ini配置说明详解(16G内存)

    通过对my.cnf/my.ini配置文件的各项关键参数进行中文注释与解析,帮助DBA及运维人员更好地理解每个配置项的作用及其对MySQL性能的影响。 #### 关键配置项详解 ##### 1. **[client]** - **port=3306**:设定MySQL...

Global site tag (gtag.js) - Google Analytics