Mysql常用命令和配置

在ubuntu下的terminal实在很方便,导致现在很少用mysql的客户端工具(除了写procedure),一直在mysql的命令行工具下开发,整理一下mysql的一些常用命令和mysql命令行配置,方便在开发中查找: mysql 配置

##Ubuntu下mysql中文乱码的配置:

修改/etc/mysql/my.cnf文件
[client]
default-character-set=utf8   --增加
[mysqld]下增加
default-character-set=utf8
init_connect='SET NAMES utf8'
[mysql]
default-character-set=utf8  --增加
重启mysql服务器:
$sudo /etc/init.d/mysql restart ##Ubuntu下mysql开放远程连接:

root登录mysql server,执行:
grant all PRIVILEGES on DBName.TableName to UserName@'IP' identified by 'password' 
flush privileges;
grant all PRIVILEGES on *.* to root@% identified by 'password'  对所有用户开放
$sudo vi /etc/mysql/my.cnf
寻找:bind-address = 127.0.0.1 ,将其注释掉(#bind-address = 127.0.0.1)
$sudo /etc/init.d/mysql restart ##mysql client 设置

pager less -n -i -S   --查询结果忽略大小写,显示行号,长行分段 ##mysql 有用的命令

grant select,insert,update on mydb.* to NewUserName@HostName identified by "password";
show grants for user;
show index from tablename;
show variables;
show processlist;
show engines;
show full columns from tablename;
mysqldump -u root -h localhost -p db < xx.sql ##mysql Explain 解释

table  *显示这一行的数据是关于哪张表的*
type  *这是重要的列,显示连接使用了何种类型。从最好到最差的连接类型为const、eq_reg、ref、range、indexhe和ALL*
possible_keys *显示可能应用在这张表中的索引。如果为空,没有可能的索引。可以为相关的域从WHERE语句中选择一个合适的语句*
key *实际使用的索引。如果为NULL,则没有使用索引*
key_len *使用的索引的长度。在不损失精确性的情况下,长度越短越好*
ref *显示索引的哪一列被使用了,如果可能的话,是一个常数*
rows *MYSQL认为必须检查的用来返回请求数据的行数*
Extra *以看到的坏的例子是Using temporary和Using filesort,意思MYSQL根本不能使用索引,结果是检索会很慢* ![alt text][1] >这篇文章会同步更新内容。 (原创文章)
135 Words 26 October 2011 Suzhou, China