标签:version current tables 数据库 mysql utf8
1 登录数据库
amp1:~ # mysql -uroot -pmysql.rzrk Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2132 Server version: 5.0.95-log SUSE MySQL RPM Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
2 使用xiaobing库
mysql> use xiaobing; Database changed
3 查xiaobing库中的表
mysql> show tables; +--------------------+ | Tables_in_xiaobing | +--------------------+ | luzhi | | t1 | +--------------------+ 2 rows in set (0.00 sec)
4 查表luzhi的表结构
mysql> desc luzhi; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name | char(30) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
5 查看表luzhi的数据
mysql> seclect * from luzhi; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘seclect * from luzhi‘ at line 1 mysql> select * from luzhi; +------+-------+ | id | name | +------+-------+ | 2 | o` | | 4 | f | +------+-------+ 4 rows in set (0.00 sec) ##发现输出为乱码
6 查当前数据库所使用的字符编码
mysql> show variables like "character%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | gbk | | character_set_connection | gbk | | character_set_database | gbk | | character_set_filesystem | binary | | character_set_results | gbk | | character_set_server | gbk | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
7 临时性的更改当前的数据编码
set names utf8;
相当于:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;
mysql> set names utf8; Query OK, 0 rows affected (0.00 sec)
8 查看是否成功修改了
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 | gbk | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) 9 再次查询表luzhi的数据,发现可以正常显示 mysql> select * from luzhi; +------+---------+ | id | name | +------+---------+ | 2 | 你好 | | 4 | 甪直 | +------+---------+ 4 rows in set (0.01 sec)
10 上面的方法只是临时的更改,当退出mysql再次进入的就会失效了。
永久更改:
#vim /etc/my.cnf [client] #password = your_password port = 3306 socket = /var/lib/mysql/mysql.sock default-character-set=gbk #这里可以设置你所需要定义的编码 utf8 # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock datadir = /home/rzrk/mysql skip-locking key_buffer = 16M max_allowed_packet = 1M table_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=gbk #这里可以设置你所需要定义的编码 utf8
修改完成后必须重启mysql才能生效
#service mysql restart #mysql uroot -p > show variables like "character%";
本文出自 “天道酬勤” 博客,请务必保留此出处http://luzhi1024.blog.51cto.com/8845546/1651596
标签:version current tables 数据库 mysql utf8
原文地址:http://luzhi1024.blog.51cto.com/8845546/1651596