mysql資料庫應用管理

來源:互聯網
上載者:User

標籤: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資料庫應用管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.