参考 http://xyfxh.spaces.live.com/Blog/cns!4EFEB1E6EFF8C824!151.entry
http://border.iteye.com/blog/116537
增加用户和密码,设定localhost,全部,特定区域都能访问
grant all privileges on qbake100617.* to likun@localhost Identified by "123456";
grant all privileges on qbake100617.* to likun@"%" Identified by "123456";
grant all privileges on qbake100617.* to likun@"%.mydomain.com" Identified by "123456";
导入sql
mysql -h localhost -u root -p mydb2 < e:\mysql\mydb2.sql
设定编码
务必注意设定的时候是utf8不是utf-8,多条横杠就杯具了。
查看系统的字符集和排序方式的设定可以通过下面的两条命令或mysql> status 。
mysql> SHOW VARIABLES LIKE 'character_set_%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | latin1 | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 7 rows in set (0.00 sec) mysql> SHOW VARIABLES LIKE 'collation_%'; +----------------------+-------------------+ | Variable_name | Value | +----------------------+-------------------+ | collation_connection | latin1_swedish_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +----------------------+-------------------+ 3 rows in set (0.00 sec) mysql> status -------------- mysql Ver 14.12 Distrib 5.0.45, for pc-linux-gnu (i686) using readline 5.0 Connection id: 17 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.0.45-community MySQL Community Edition (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /var/lib/mysql/mysql.sock Uptime: 50 min 34 sec Threads: 15 Questions: 2413 Slow queries: 0 Opens: 13 Flush tables: 1 Open tables: 8 Queries per second avg: 0.795 --------------
1. SET NAMES 'utf8';
它相当于下面的三句指令:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;
2. 创建数据库
mysql> create database name character set utf8;
3. 创建表
CREATE TABLE `type` (
`id` int(10) unsigned NOT NULL auto_increment,
`flag_deleted` enum('Y','N') character set utf8 NOT NULL default 'N',
`flag_type` int(5) NOT NULL default '0',
`type_name` varchar(50) character set utf8 NOT NULL default '',
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
4. 修改数据库成utf8的.
mysql> alter database name character set utf8;
5. 修改表默认用utf8.
mysql> alter table type character set utf8;
6. 修改字段用utf8
mysql> alter table type modify type_name varchar(50) CHARACTER SET utf8;
7 在/etc/下找到my.cnf,如果没有就把MySQL的安装目录下的support-files目录下的my-medium.cnf复制到/etc/下并改名为my.cnf即可
打开my.cnf以后,在[client]和[mysqld]下面均加上default-character-set=utf8,保存并关闭