標籤: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;
亂碼
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
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資料庫應用管理