mysql数据库应用管理

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql数据库应用管理相关的知识,希望对你有一定的参考价值。

insert

测试表mysql> show create  table test\G

create  table test(

id int(4)  not  null   AUTO_INCREMENT,

name char(20) not null,

primary  key(id)

);

mysql> insert    into   test(id,name)  value(1,‘hequan‘);

mysql> select * from test;

mysql> insert into test(name)  value(‘hequan‘);  //ID是自增的,可以插name

mysql>  insert into test  value(3,‘hequna‘),(4,‘hequan‘);  // 不给列,直接按顺序插入

 mysqldump -uroot -p123456 -B oldboy >/tmp/oldboy_bak.sql  //备份数据库 备份用检查一遍

grep -E -v "#|\/|^$|--"  /tmp/oldboy_bak.sql 


select           from            where 

mysql> select id,name from test  where name=‘hequan‘  and/or  id=4;

mysql> select id,name from test   limit 0,2; //从第0行开始,查2行

mysql> select id,name from test  where id>2 and id<4;

mysql> select id,name from test   order by id     asc/desc;

多表查询

mysql> select student.Sno,student.Sname,course.Cname,SC.Grade  from student,course,SC   where  student.Sno=SC.Sno and  course.Cno=SC.Cno  order by Sno ;

mysql> explain  select * from test where name=‘hequan‘\G;//执行过程  判断有么有走索引

possible_keys: NULL

rows: 2

mysql> create index index_name on test(name);

possible_keys: index_name

rows: 1


update

mysql> update   test set  name=‘xx‘   where   id=4   ;

 mysql -uroot -p123456 oldboy < /tmp/oldboy_bak.sql //恢复数据,增量恢复


增量恢复  

#log-bin=mysql-bin  打开

/application/mysql/data/mysql-bin-hequan.000001

mysqlbinlog mysql-bin-hequan.000001


 mysqladmin -uroot -p123456  flush-log 切割日志

mysql-bin-hequan.000002


 mysqlbinlog -d oldboy mysql-bin-hequan.000001  >bin.sql

把错误的语句删除掉

mysql  -uroot -p123456 oldboy  <bin.sql

binlog只记录主数据库更改 


delete

mysql> delete from  test  where id=3;   > <

mysql> truncate table test;  //清空表


更改表的字段

mysql> alter table test add sex  char(4)  after name;  //在name后面添加sex  // first


mysql> rename   table test to test1;

mysql> alter table test1 rename to test;


mysql> drop table test;


乱码

技术分享

set  names  latin1  


cat  /etc/sysconfig/i18n        //系统环境

LANG="zh_CN.UTF-8"


vim  /etc/my.cnf                    //服务器端 和客户端

[client]

default-charater-set=latin1

[mysqld]

character-set-server=utf8          //5.5版本

 ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8


 




本文出自 “何全” 博客,请务必保留此出处http://hequan.blog.51cto.com/5701886/1773918

以上是关于mysql数据库应用管理的主要内容,如果未能解决你的问题,请参考以下文章

Mysql账号管理

python+mysql+flask创建一个微博应用(持续更新)

MySQL的DML语言(增删改)

MySQL数据库应用DML语句之insert知识

mysql四:数据操作

MySql insert into 失败?