vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8 (数据库缺省以utf8存储)
init_connect='SET NAMES utf8' (设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行)
[client]
default-character-set=utf8 (客户端缺省以utf8存储)
重启mysql
登陆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 | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
2010年1月18日 更新:
导入导出数据:
mysqldump db > table.sql
可选参数:
-n : --no-create-db
-t : --no-create-table
-d : --no-data
数据导出:mysqldump --default-character-set=gbk db > db.sql
数据导入:mysql --default-character-set=gbk db < db.sql
执行mysqldump sql:mysqldump -w "fmodify_date > '2010-4-10'"
执行指令后导出txt:mysql -uroot -p123 db_fund -e "select * from t_fund_bind limit 0,10" > bind.sql
修改字符集:
alter database da_name default character set 'gbk'
set names 'gbk'
set names gbk告诉mysql,接下来的数据将以该编码方式传输,等同于:
SET character_set_client = gbk;
SET character_set_results = gbk;
SET character_set_connection = gbk;
通过status指令查看当前的编码:
mysql> status;
Server characterset: latin1
Db characterset: gbk
Client characterset: gbk
Conn. characterset: gbk
7)导入我们转换成gbk后的文件
mysql> source base_user_gbk.sql;
用户命令:
mysql> CREATE USER yy IDENTIFIED BY '123';
yy表示你要建立的用户名,后面的123表示密码
上面建立的用户可以在任何地方登陆。
如果要限制在固定地址登陆,比如localhost 登陆:
mysql> CREATE USER yy@localhost IDENTIFIED BY '123';
mysql> GRANT ALL PRIVILEGES ON *.* TO user@localhost
grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";
格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
修改密码:
mysql> grant all privileges on pureftpd.* to koko@localhost identified by 'mimi';
flush:
mysql> flush privileges;
--转自