Mysql解决中文乱码

本文详细介绍了如何解决MySQL数据库中的中文乱码问题,包括检查和修改数据库、表以及连接的字符集设置。通过修改my.ini或my.cnf文件并重启MySQL服务,确保所有环节使用utf8编码,从而实现对中文字符的支持。此外,还提供了临时解决乱码问题的方法,如在SQL会话中设置字符集。
摘要由CSDN通过智能技术生成

mysql字符编码的设置以及mysql中文乱码的解决方法(治本)

2.1解决策略一:

最近在开发过程中,使用到mysql的数据库,而在将中文数据插入到数据库的时候出现了数据乱码的问题,在网上找了很多方法,问了很多人,试了很久才发现网上有的方法是不行的,因此在此记录下,以便他人查找。

查看字符编码

首先,将中文插入到数据库乱码是因为没有将数据库编码设置为支持中文的编码,mysql的默认编码是Latin1,不支持中文,应该设置为utf8查看自己的数据库编码是否已设置好,进入数据库,输入:show variables like "char%",如果出现下面的结果

 说明你的数据库编码正确,无需修改,应该是页面或者其他编码的问题。如果跟上面的结果不同,说明需要修改数据库的编码。

在windows系统下

1、在mysql的安装目录下找到my.ini文件(如果没有的话就把my-medium.ini复制,然后重命名为my.ini即可)

2、在my.ini文件中找到[client]和[mysqld]字段,在下面均加上default-character-set=utf8,保存并关闭

3、重启mysql服务

在linux系统下

1、打开配置文件,我使用的linux版本是ubuntu,配置文件在/etc/mysql/my.cnf

2、在[client]和[mysqld]字段下面均添加default-character-set=utf8,保存并关闭

3、重启mysql服务

注意:

如果重启成功,并查看数据库编码,如果结果如下

 恭喜你,说明你已经修改成功了

如果在linux下重启mysql服务的时候出现Job failed to start,在window下重启失败,这是因为你安装了高版本的mysql(mysql5.5以上),在高版本对字符编码方式修改的办法中,在[mysqld]下的修改发生了变化,正确方式如下:

[mysqld]下添加的应该为:

character-set-server=utf8

collation-server=utf8_general_ci

重启mysql,现在再次查看字符编码,如果跟下面一致,说明成功了

好吧,以上就是mysql字符乱码问题的解决,自己想记录下来,方便自己以后再次用到或者为别人需要是查阅,如果有错误的地方,请指出,谢谢。

----------------------------------------------------------------------

2.2解决策略二(治标):

MySQL会出现中文乱码的原因不外乎下列几点:

1.server本身设定问题,例如还停留在latin1

2.table的语系设定问题(包含character与collation)

3.客户端程式(例如php)的连线语系设定问题

强烈建议使用utf8!!!!

utf8可以兼容世界上所有字符!!!!

一、避免创建数据库及表出现中文乱码和查看编码方法

1、创建数据库的时候:

CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';

2、建表的时候 

CREATE TABLE `database_user` (  
   `ID` varchar(40) NOT NULL default '',  
   `UserID` varchar(40) NOT NULL default '',  
) ENGINE=InnoDB DEFAULT CHARSET=utf8;  


这3个设置好了,基本就不会出问题了,即建库和建表时都使用相同的编码格式。

但是如果你已经建了库和表可以通过以下方式进行查询。

1.查看默认的编码格式:

mysql> show variables like "%char%";  
+--------------------------+---------------+  
| Variable_name | Value |  
+--------------------------+---------------+  
| character_set_client | gbk |  
| character_set_connection | gbk |  
| character_set_database | utf8 |  
| character_set_filesystem | binary |  
| character_set_results | gbk |  
| character_set_server | utf8 |  
| character_set_system | utf8 |   
+--------------------------+-------------+  

注:以前2个来确定,可以使用set names utf8,set names gbk设置默认的编码格式;

     1. 执行SET NAMES utf8的效果等同于同时设定如下:


SET character_set_client='utf8';   
SET character_set_connection='utf8';  
SET character_set_results='utf8'; 

2.查看test数据库的编码格式:


mysql> show create database test;  
+------------+------------------------------------------------------------------------------------------------+  
| Database | Create Database |  
+------------+------------------------------------------------------------------------------------------------+  
| test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET gbk */ |  
+------------+------------------------------------------------------------------------------------------------+  

3.查看yjdb数据表的编码格式:


mysql> show create table yjdb;  
| yjdb | CREATE TABLE `yjdb` (  
`sn` int(5) NOT NULL AUTO_INCREMENT,  
`type` varchar(10) NOT NULL,  
`brc` varchar(6) NOT NULL,  
`teller` int(6) NOT NULL,  
`telname` varchar(10) NOT NULL,  
`date` int(10) NOT NULL,  
`count` int(6) NOT NULL,  
`back` int(10) NOT NULL,  
PRIMARY KEY (`sn`),  
UNIQUE KEY `sn` (`sn`),  
UNIQUE KEY `sn_2` (`sn`)  
) ENGINE=MyISAM AUTO_INCREMENT=1826 DEFAULT CHARSET=gbk ROW_FORMAT=DYNAMIC |  

二、避免导入数据有中文乱码的问题

1:将数据编码格式保存为utf-8

设置默认编码为utf8:

set names utf8;

设置数据库db_name默认为utf8:


ALTER DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 

设置表tb_name默认编码为utf8:


ALTER TABLE `tb_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;  

导入:


LOAD DATA LOCAL INFILE 'C:\\utf8.txt' INTO TABLE yjdb; 

2:将数据编码格式保存为ansi(即GBK或GB2312)

设置默认编码为gbk:

set names gbk;

设置数据库db_name默认编码为gbk:


ALTER DATABASE `db_name` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; 

设置表tb_name默认编码为gbk:


ALTER TABLE `tb_name` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; 

导入:


LOAD DATA LOCAL INFILE 'C:\\gbk.txt' INTO TABLE yjdb;  

注:1.UTF8不要导入gbk,gbk不要导入UTF8;

       2.dos下不支持UTF8的显示;

三、解决网页中乱码的问题

 将网站编码设为 utf-8,这样可以兼容世界上所有字符。

  如果网站已经运作了好久,已有很多旧数据,不能再更改简体中文的设定,那么建议将页面的编码设为 GBK, GBK与GB2312的区别就在于:GBK能比GB2312显示更多的字符,要显示简体码的繁体字,就只能用GBK。

1.编辑/etc/my.cnf ,在[mysql]段加入default_character_set=utf8;

2.在编写Connection URL时,加上?useUnicode=true&characterEncoding=utf-8参;

3.在网页代码中加上一个"set names utf8"或者"set names gbk"的指令,告诉MySQL连线内容都要使用

utf8或者gbk;

2.3操作步骤(文件中红色字体部分)

点主页找该文件 已上传分享

Last login: Thu Nov 16 01:47:21 on ttys000
keideMacBook-Pro:~ jinye$ sudo sush-3.2# /usr/local/mysql/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 11
Server version: 5.1.63-log MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| emp                |
| emp1               |
| mysql              |
| ttms               |
+--------------------+
5 rows in set (0.00 sec)
mysql> 

mysql> use emp;
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>
mysql>
mysql> select * from student;
+----+------+------+------------+------+------------+------------+---------+----------+
| id | name | tsex | department | age  | birthplace | birthdate  | einheit | salary   |
+----+------+------+------------+------+------------+------------+---------+----------+
|  1 | ??   | m    | ????       |   31 | ??         | 1986-03-21 | ??      |  5000.00 |
|  2 | ???  | m    | ????       |   28 | ??         | 1986-06-21 | ??      |  3000.00 |
|  3 | ??   | w    | ??         |   18 | ??         | 1999-07-02 | ??      |  9000.00 |
|  4 | ??   | m    | ????       |   43 | ??         | 1974-03-21 | ??      |  2000.00 |
|  5 | ???  | w    | ????       |   24 | ??         | 1993-05-14 | ??      |  4000.00 |
|  6 | ???  | m    | ???        |   89 | ??         | 1928-03-21 | ??      |  9000.00 |
|  7 | ???  | m    | ????       |   34 | ??         | 1983-03-21 | ??      |  9000.00 |
|  8 | ??   | m    | ????       |   43 | ??         | 1974-11-06 | ??      | 10000.00 |
|  9 | ???  | w    | ??         |   18 | ??         | 1999-12-21 | ??      | 20000.00 |
| 10 | ???  | m    | ????       |   43 | ??         | 1974-05-14 | ??      |  2000.00 |
| 11 | ??   | m    | ????       |   34 | ??         | 1983-03-16 | ??      |  3000.00 |
| 12 | ??   | m    | ????       |   26 | ??         | 1991-03-21 | ??      |  3000.00 |
| 13 | ???  | m    | ????       |   43 | ??         | 1974-04-19 | ??      |  9000.00 |
| 14 | ??   | m    | ????       |   31 | ??         | 1986-05-14 | ??      |  3000.00 |
| 15 | ???  | w    | ????       |   28 | ??         | 1989-03-21 | ??      |  2000.00 |
+----+------+------+------------+------+------------+------------+---------+----------+
15 rows in set (0.00 sec)
mysql> show variables like "%char%";
+--------------------------+--------------------------------------------------------+
| Variable_name            | Value                                                  |
+--------------------------+--------------------------------------------------------+
| character_set_client     | latin1                                                |
| character_set_connection | latin1                                                 |
| character_set_database   | utf8                                                   |
| character_set_filesystem | binary                                                 |
| character_set_results    | latin1                                                 |
| character_set_server     | latin1                                                |
| character_set_system     | utf8                                                   |
| character_sets_dir       | /usr/local/mysql-5.1.63-osx10.6-x86_64/share/charsets/ |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.00 sec)
mysql> SET character_set_client='utf8';
Query OK, 0 rows affected (0.00 sec)
mysql> SET character_set_connection='utf8';
Query OK, 0 rows affected (0.00 sec)
mysql> SET character_set_results='utf8';
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like "%char%";
+--------------------------+--------------------------------------------------------+
| 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/local/mysql-5.1.63-osx10.6-x86_64/share/charsets/ |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.00 sec)
mysql>
mysql>
mysql> SET character_set_server='utf8';
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>
mysql>
mysql> select * from student;
+----+-----------+------+--------------+------+------------+------------+---------+----------+
| id | name      | tsex | department   | age  | birthplace | birthdate  | einheit | salary   |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
|  1 | 周瑜    | m    | 行政管理 |   31 | 浙江    | 1986-03-21 | 三国  |  5000.00 |
|  2 | 鲁智深 | m    | 市场营销 |   28 | 山东    | 1986-06-21 | 宋朝  |  3000.00 |
|  3 | 貂蝉    | w    | 舞蹈      |   18 | 浙江    | 1999-07-02 | 三国  |  9000.00 |
|  4 | 黄忠    | m    | 市场营销 |   43 | 湖南    | 1974-03-21 | 三国  |  2000.00 |
|  5 | 花木兰 | w    | 市场营销 |   24 | 湖南    | 1993-05-14 | 汉朝  |  4000.00 |
|  6 | 张三丰 | m    | 宗教学    |   89 | 福建    | 1928-03-21 | 明朝  |  9000.00 |
|  7 | 陈独秀 | m    | 国际政治 |   34 | 安徽    | 1983-03-21 | 民国  |  9000.00 |
|  8 | 曹操    | m    | 行政管理 |   43 | 安徽    | 1974-11-06 | 三国  | 10000.00 |
|  9 | 陈圆圆 | w    | 舞蹈      |   18 | 江苏    | 1999-12-21 | 明朝  | 20000.00 |
| 10 | 王明阳 | m    | 古典文学 |   43 | 浙江    | 1974-05-14 | 明朝  |  2000.00 |
| 11 | 李煜    | m    | 古典文学 |   34 | 山西    | 1983-03-16 | 唐朝  |  3000.00 |
| 12 | 罗成    | m    | 市场营销 |   26 | 山西    | 1991-03-21 | 唐朝  |  3000.00 |
| 13 | 李世民 | m    | 行政管理 |   43 | 山西    | 1974-04-19 | 唐朝  |  9000.00 |
| 14 | 孙策    | m    | 行政管理 |   31 | 浙江    | 1986-05-14 | 三国  |  3000.00 |
| 15 | 李清照 | w    | 古典文学 |   28 | 山东    | 1989-03-21 | 宋朝  |  2000.00 |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
15 rows in set (0.00 sec)

--------------------------------

操作完后发现重新启动mysql又出现乱码

--------------------------------

mysql>
mysql>
mysql>
mysql> use emp;
Database changed
mysql>
mysql>
mysql> select * from student;
+----+-----------+------+--------------+------+------------+------------+---------+----------+
| id | name      | tsex | department   | age  | birthplace | birthdate  | einheit | salary   |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
|  1 | 周瑜    | m    | 行政管理 |   31 | 浙江    | 1986-03-21 | 三国  |  5000.00 |
|  2 | 鲁智深 | m    | 市场营销 |   28 | 山东    | 1986-06-21 | 宋朝  |  3000.00 |
|  3 | 貂蝉    | w    | 舞蹈      |   18 | 浙江    | 1999-07-02 | 三国  |  9000.00 |
|  4 | 黄忠    | m    | 市场营销 |   43 | 湖南    | 1974-03-21 | 三国  |  2000.00 |
|  5 | 花木兰 | w    | 市场营销 |   24 | 湖南    | 1993-05-14 | 汉朝  |  4000.00 |
|  6 | 张三丰 | m    | 宗教学    |   89 | 福建    | 1928-03-21 | 明朝  |  9000.00 |
|  7 | 陈独秀 | m    | 国际政治 |   34 | 安徽    | 1983-03-21 | 民国  |  9000.00 |
|  8 | 曹操    | m    | 行政管理 |   43 | 安徽    | 1974-11-06 | 三国  | 10000.00 |
|  9 | 陈圆圆 | w    | 舞蹈      |   18 | 江苏    | 1999-12-21 | 明朝  | 20000.00 |
| 10 | 王明阳 | m    | 古典文学 |   43 | 浙江    | 1974-05-14 | 明朝  |  2000.00 |
| 11 | 李煜    | m    | 古典文学 |   34 | 山西    | 1983-03-16 | 唐朝  |  3000.00 |
| 12 | 罗成    | m    | 市场营销 |   26 | 山西    | 1991-03-21 | 唐朝  |  3000.00 |
| 13 | 李世民 | m    | 行政管理 |   43 | 山西    | 1974-04-19 | 唐朝  |  9000.00 |
| 14 | 孙策    | m    | 行政管理 |   31 | 浙江    | 1986-05-14 | 三国  |  3000.00 |
| 15 | 李清照 | w    | 古典文学 |   28 | 山东    | 1989-03-21 | 宋朝  |  2000.00 |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
15 rows in set (0.01 sec)
mysql>
mysql>
mysql>
mysql> use emp1;
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>
mysql>
mysql> select * from student;
+----+-----------+------+--------------+------+------------+------------+---------+----------+
| id | name      | tsex | department   | age  | birthplace | birthdate  | einheit | salary   |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
|  1 | 周瑜    | m    | 行政管理 |   31 | 浙江    | 1986-03-21 | 三国  |  5000.00 |
|  2 | 鲁智深 | m    | 市场营销 |   28 | 山东    | 1986-06-21 | 宋朝  |  3000.00 |
|  3 | 貂蝉    | w    | 舞蹈      |   18 | 浙江    | 1999-07-02 | 三国  |  9000.00 |
|  4 | 黄忠    | m    | 市场营销 |   43 | 湖南    | 1974-03-21 | 三国  |  2000.00 |
|  5 | 花木兰 | w    | 市场营销 |   24 | 湖南    | 1993-05-14 | 汉朝  |  4000.00 |
|  6 | 张三丰 | m    | 宗教学    |   89 | 福建    | 1928-03-21 | 明朝  |  9000.00 |
|  7 | 陈独秀 | m    | 国际政治 |   34 | 安徽    | 1983-03-21 | 民国  |  9000.00 |
|  8 | 曹操    | m    | 行政管理 |   43 | 安徽    | 1974-11-06 | 三国  | 10000.00 |
|  9 | 陈圆圆 | w    | 舞蹈      |   18 | 江苏    | 1999-12-21 | 明朝  | 20000.00 |
| 10 | 王明阳 | m    | 古典文学 |   43 | 浙江    | 1974-05-14 | 明朝  |  2000.00 |
| 11 | 李煜    | m    | 古典文学 |   34 | 山西    | 1983-03-16 | 唐朝  |  3000.00 |
| 12 | 罗成    | m    | 市场营销 |   26 | 山西    | 1991-03-21 | 唐朝  |  3000.00 |
| 13 | 李世民 | m    | 行政管理 |   43 | 山西    | 1974-04-19 | 唐朝  |  9000.00 |
| 14 | 孙策    | m    | 行政管理 |   31 | 浙江    | 1986-05-14 | 三国  |  3000.00 |
| 15 | 李清照 | w    | 古典文学 |   28 | 山东    | 1989-03-21 | 宋朝  |  2000.00 |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
15 rows in set (0.00 sec)
mysql> exit
Bye
sh-3.2# 

--------------------------------

更改配置文件

--------------------------------

sh-3.2#
sh-3.2#
sh-3.2# cd /usr/local/mysql
sh-3.2#
sh-3.2#
sh-3.2# ll
sh: ll: command not found
sh-3.2#
sh-3.2# ls
COPYING bin include mysql-test sql-bench
INSTALL-BINARY data lib scripts support-files
README docs man share
sh-3.2# cd bin
sh-3.2#
sh-3.2# ls
innochecksum mysql_secure_installation mysqld_safe
msql2mysql mysql_setpermission mysqldump
my_print_defaults mysql_tzinfo_to_sql mysqldumpslow
myisam_ftdump mysql_upgrade mysqlhotcopy
myisamchk mysql_waitpid mysqlimport
myisamlog mysql_zap mysqlmanager
myisampack mysqlaccess mysqlshow
mysql mysqlaccess.conf mysqlslap
mysql_client_test mysqladmin mysqltest
mysql_client_test_embedded mysqlbinlog mysqltest_embedded
mysql_config mysqlbug perror
mysql_convert_table_format mysqlcheck replace
mysql_find_rows mysqld resolve_stack_dump
mysql_fix_extensions mysqld-debug resolveip
mysql_fix_privilege_tables mysqld_multi
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2# sudo cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
sh-3.2#
sh-3.2#
sh-3.2# sudo vi /etc/my.cnf
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2# more /etc/my.cnf
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock
default-character-set=utf8
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
default-character-set=utf8
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id       = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2#
sh-3.2# /usr/local/mysql/bin/mysql -u root -p;
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.63-log MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql>
mysql>
mysql> show variables like "%char%"; 
+--------------------------+--------------------------------------------------------+
| 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     | utf8                                                   |
| character_set_system     | utf8                                                   |
| character_sets_dir       | /usr/local/mysql-5.1.63-osx10.6-x86_64/share/charsets/ |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> use emp ;
Database changed
mysql>
mysql>
mysql> select * from student;
+----+-----------+------+--------------+------+------------+------------+---------+----------+
| id | name      | tsex | department   | age  | birthplace | birthdate  | einheit | salary   |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
|  1 | 周瑜      | m    | 行政管理    |   31 | 浙江      | 1986-03-21 | 三国    |  5000.00 |
|  2 | 鲁智深    | m    | 市场营销    |   28 | 山东      | 1986-06-21 | 宋朝    |  3000.00 |
|  3 | 貂蝉      | w    | 舞蹈        |   18 | 浙江      | 1999-07-02 | 三国    |  9000.00 |
|  4 | 黄忠      | m    | 市场营销    |   43 | 湖南      | 1974-03-21 | 三国    |  2000.00 |
|  5 | 花木兰    | w    | 市场营销    |   24 | 湖南      | 1993-05-14 | 汉朝    |  4000.00 |
|  6 | 张三丰    | m    | 宗教学      |   89 | 福建      | 1928-03-21 | 明朝    |  9000.00 |
|  7 | 陈独秀    | m    | 国际政治    |   34 | 安徽      | 1983-03-21 | 民国    |  9000.00 |
|  8 | 曹操      | m    | 行政管理    |   43 | 安徽      | 1974-11-06 | 三国    | 10000.00 |
|  9 | 陈圆圆    | w    | 舞蹈        |   18 | 江苏      | 1999-12-21 | 明朝    | 20000.00 |
| 10 | 王明阳    | m    | 古典文学    |   43 | 浙江      | 1974-05-14 | 明朝    |  2000.00 |
| 11 | 李煜      | m    | 古典文学    |   34 | 山西      | 1983-03-16 | 唐朝    |  3000.00 |
| 12 | 罗成      | m    | 市场营销    |   26 | 山西      | 1991-03-21 | 唐朝    |  3000.00 |
| 13 | 李世民    | m    | 行政管理    |   43 | 山西      | 1974-04-19 | 唐朝    |  9000.00 |
| 14 | 孙策      | m    | 行政管理    |   31 | 浙江      | 1986-05-14 | 三国    |  3000.00 |
| 15 | 李清照    | w    | 古典文学    |   28 | 山东      | 1989-03-21 | 宋朝    |  2000.00 |
+----+-----------+------+--------------+------+------------+------------+---------+----------+
15 rows in set (0.00 sec)
mysql>
mysql>
mysql>

——————————————————————

注:

删除文件:rm -rf 文件名

进入目录:cd /目录

编辑文件 :vi 文件名

查看文件内容:cat 文件名

保存文件:是:wq!

复制文件 :cp 文件1 文件2


  • 4
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

从码农到码到成功

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值