1、首先打開MYSQL的管理工具,新建一個test表,并且在表中插入兩個字段。

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:申請域名、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、建寧網(wǎng)站維護、網(wǎng)站推廣。
2、接下來在Editplus編輯器中創(chuàng)建一個PHP文件,進行數(shù)據(jù)庫連接,并且選擇要操作的數(shù)據(jù)庫。
3、然后通過mysql_query方法執(zhí)行一個Insert的插入語句。
4、執(zhí)行完畢以后,回到數(shù)據(jù)庫管理工具中,這個時候你會發(fā)現(xiàn)插入的中文亂碼了。
5、接下來在PHP文件中通過mysql_query執(zhí)行一個set? names? utf8語句。
6、接下來執(zhí)行以后回到MYSQL數(shù)據(jù)庫中,發(fā)現(xiàn)插入的中文顯示正常了,即成功往mysql中寫入數(shù)據(jù)了。
1、使用 create table 語句可完成對表的創(chuàng)建, create table 的創(chuàng)建形式:
create table 表名稱(列聲明);
以創(chuàng)建 people 表為例, 表中將存放 學號(id)、姓名(name)、性別(sex)、年齡(age) 這些內(nèi)容:
create table people(
id int unsigned not null auto_increment primary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null
);
其中,auto_increment就可以使Int類型的id字段每次自增1。
2、向表中插入數(shù)據(jù)使用insert 語句。
insert 語句可以用來將一行或多行數(shù)據(jù)插到數(shù)據(jù)庫表中, 使用的一般形式如下:
insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, ...);
其中 [] 內(nèi)的內(nèi)容是可選的, 例如, 要給上步中創(chuàng)建的people 表插入一條記錄, 執(zhí)行語句:
insert into people(name,sex,age) values( "張三", "男", 21 );
3、想要查詢是否插入成功,可以通過select 查詢語句。形式如下:
select * from people;
擴展資料:
當mysql大批量插入數(shù)據(jù)的時候使用insert into就會變的非常慢,?mysql提高insert into 插入速度的方法有三種:
1、第一種插入提速方法:
如果數(shù)據(jù)庫中的數(shù)據(jù)已經(jīng)很多(幾百萬條), 那么可以?加大mysql配置中的 bulk_insert_buffer_size,這個參數(shù)默認為8M
舉例:bulk_insert_buffer_size=100M;
2、第二種mysql插入提速方法:
改寫所有 insert into 語句為?insert?delayed into
這個insert delayed不同之處在于:立即返回結(jié)果,后臺進行處理插入。
3、第三個方法: 一次插入多條數(shù)據(jù):
insert中插入多條數(shù)據(jù),舉例:
insert into table values('11','11'),('22','22'),('33','33')...;
1、先添加完,刪除所有重復(fù)的記錄,再insert一次
insert into A select * from B;
insert into A select * from C;
insert into A select * from D;
2、刪除重復(fù)的記錄只保留一行
delete from A where name in (select id from t1 group by id having count(id) 1)and rowid not in (select min(rowid) from t1 group by id having
count(*)1);
3、記錄一下這些重復(fù)的記錄,
mysql -uroot -p123456 -Ddb01 -e 'select b.id from t1 b group by id having count(b.id) 1' | tail -n +2 repeat.txt
刪除全部重復(fù)的記錄
delete from A where name in (select name from t1 group by name having count(name) 1;);
再次插入多刪的重復(fù)記錄
#!/bin/sh
for id1 in `cat repeat.txt`;do
mysql -uroot -p123456 -Ddb01 -e "insert into A select * from B where id='${id1}'"
done
分享文章:mysql怎么添加表記錄 mysql如何在表中添加數(shù)據(jù)
路徑分享:http://chinadenli.net/article26/hjiijg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導航、網(wǎng)站改版、網(wǎng)站策劃、做網(wǎng)站、自適應(yīng)網(wǎng)站、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)