A. mysql問題,聊天功能,所有用戶聊天信息都存在一個表裡還是每個用戶自動生成一個表
一般情況下的話,我覺得像這個問題的話,如果說喜歡聽你聊天功能的話,所以就會鍛煉身體,都存在一個表裡,然後我覺得那樣,不是因為我覺得一般情況下的話,所有的信息的話,它都是會有一個衡陽成立了這個列表才可以的。
B. MySQL 表的信息存放在什麼地方
查看my.ini文件,一般存放在datadir的路徑中,Myisam由3種描述文件組成,以abc資料庫為例,3個表文件分別為 abc.frm 、abd.myi、abc.myd,innodb的則另行存儲在一個文件中,一般是大於一定尺寸的才放到這個目錄中。
C. mysql怎樣導出表(表結構+數據)
定期的備份可使我們資料庫崩潰造成的損失大大降低。在MySQL中進行數據備份的方法有兩種,一種是使用mysqlmp程序,一種是使用mysqlhot、cp、tar或cpio等打包程序直接拷貝資料庫文件。mysqlmp程序備份資料庫較慢,但它生成的文本文件便於移植。使用mysqlhot等程序備份速度快,因為它直接對系統文件進行操作,需人為協調資料庫數據的備份前後一致性。
使用mysqlmp備份資料庫其實就是把資料庫轉儲成一系列CREATE TABLE和INSERT語句,通過這些語句我們就可重新生成資料庫。使用mysqlmp的方法如下:
% mysqlmp --opt testdb | gzip > /data/backup/testdb.bak
#--opt選項會對轉儲過程進行優化,生成的備份文件會小一點,後的管道操作會進行數據壓縮
% mysqlmp --opt testdb mytable1,mytable2 | gzip > /data/backup/testdb_mytable.bak
#可在資料庫後接數據表名,只導出指定的數據表,多個數據表可用逗號分隔
--opt選項還可激活--add-drop-table選項,它將會在備份文件的每條CREATE TABLE前加上一條DROP TABLE IF EXISTS語句。這可方便進行數據表的更新,而不會發生「數據表已存在」的錯誤。
用mysqlmp命令還可直接把資料庫轉移到另外一台伺服器上,不用生成備份文件。重復執行可定期更新遠程資料庫。
% mysqladmin -h remote_host create testdb
% mysqlmp --opt testdb | mysql -h remote_host testdb
另外還可通過ssh遠程調用伺服器上的程序,如:
% ssh remote_host mysqladmin create testdb
% mysqlmp --opt testdb | ssh remote_host mysql testdb
通過直接拷貝系統文件的方式備份資料庫,在備份時,要確保沒有人對資料庫進行修改操作。要做到這點,最好關閉伺服器。如果不能關閉的,要以只讀方試鎖定有關數據表。下面是一些示例:
% cp -r db /backup/db #備份db資料庫到/backup/db目錄
% cp table_name.* /backup/db #只備份table_name數據表
% scp -r db remotehot:/usr/local/mysql/data #用scp把資料庫直接拷貝到遠程伺服器
在把資料庫直接拷貝到遠程主機時,應注意兩台機器必須有同樣的硬體結構,或者將拷貝的數據表全部是可移植數據表類型。
使用mysqlhot工具,它是一個Perl DBI腳本,可在不關閉伺服器的情況下備份資料庫,它主要的優點是:
它直接拷貝文件,所以它比mysqlmp快。
可自動完成數據鎖定工作,備份時不用關閉伺服器。
能刷新日誌,使備份文件和日誌文件的檢查點能保持同步。
下面是該工具的使用示例:
% mysqlhot db /bakcup/ #把db資料庫備份到backup/db目錄里,會自動創建一個db目錄
使用BACKUP TABLE語句進行備份,該語句最早出現在MySQL 3.23.25版本中,僅適用於MyISAM數據表。用法如下:
mysql> BACKUP TABLE mytable TO '/backup/db'; #把mytable數據表備份到/backup/db目錄下
為了執行該語句,你必須擁有那些表的FILE許可權和SELECT許可權,備份目錄還必須是伺服器可寫的。該語句執行時,會先把內存中的數據寫入磁碟,再把各個數據表的.frm(表結構定義文件)、.MYD(數據)文件從數據目錄拷貝到備份目錄。它不拷貝.MYI(索引)文件,因為它能用另外兩個文件重建。BACKUP TABLE語句備份時,依次鎖定數據表,當同時備份多個數據表時,數據表可能會被修改,所以備份0完成時,備份文件中的數據和現時數據表中的數據可能會有差異,為了消除該差異,我們可用只讀方式鎖定數據表,在備份完成後再解鎖。如:
mysql> LOCK TABLES tb1 READ,tb2 READ;
mysql> BACKUP TABLE tb1,tb2 TO 'backup/db';
mysql> UNLOCK TABLES;
使用BACKUP TABLE語句備份的數據表可用RESTORE TABLE重新載入到伺服器。
InnoDB和BDB資料庫也可用mysqlmp和直接拷貝法進行備份。使用直接拷貝法時應注意需把組成InnoDB和BDB資料庫的所有文件都拷貝下來,如InnoDB的.frm文件、日誌文件和表空間配置文件;BDB的數據文件、日誌文件等。
使用鏡像機制進行備份,我們可用SLAVE STOP語句掛起從伺服器的鏡像,在從伺服器上通過直接拷貝法或其它工具製作備份。備份完成,用SLAVE START重新啟動鏡像,從伺服器重新與主伺服器同步,接收備份時主伺服器所做的修改。
在MySQL中沒有為資料庫重命名的命令,但我們可用mysqlmp轉儲資料庫,再創建一個新的空資料庫,把轉儲文件載入到該新資料庫,這樣就完成資料庫重命名的工作。如:
% mysqlmp old_db >db.sql #轉儲db資料庫數據
% mysqladmin create new_db #新建一個空的資料庫
% mysql new_db < db.sql #把db資料庫的數據載入到新的資料庫中
% mysqladmin drop old_db #刪除舊的資料庫
一個更簡單的重命名資料庫的方法是直接修改資料庫目錄名,但該方法不適用於InnoDB和BDB資料庫。注意,在更名後,需在許可權表中更新相關數據表信息,需執行以下語句:
mysql> UPDATE db SET db='new_db' WHERE db='old_db';
mysql> UPDATE tables_priv SET db='new_db' WHERE db='old_db';
mysql> UPDATE columns_priv SET db='new_db' WHERE db='old_db';
mysql> UPDATE host SET db='new_db' WHERE db='old_db';
D. mysql 存儲過程
你應該在做統計吧,估計你不會的就是mysql存儲過程的語法 我之前也寫過 很是郁悶 我給你一段代碼 是我用mysql寫過的一個存儲過程 你看看 主要是了解裡面的語法 看懂了 你所說的需求並不難
有看不懂的地方一起討論 :
begin
declare tikk datetime ;
declare done int default 0;
declare userid int default 0;
declare moleid int default 0;
declare couid int default 0;
declare mname varchar(255) ;
declare opsid int default 0;
declare c1 cursor for Select I_userID,I_operationID from space_operation_record where status<>0 group by I_userID,I_operationID order by createtime desc;
declare continue handler for sqlstate '02000' set done =1;
set tikk = now();
open c1;
repeat
fetch c1 into userid, opsid;
if not done then
select I_moleID from space_operation where status<>0 and ID=opsid into moleid;
if moleid <> '' then
select Nvc_identification from space_operation where status<>0 and ID=opsid into @identiftion;
if moleid > 0 then
Select Nvc_ename from space_mole where status<>0 and ID=moleid into mname;
else
set mname = 'space';
end if;
create temporary table if not exists sp_tab1(id bigint(20),Nvc_content MEDIUMTEXT,I_obyuID bigint(20),I_tID bigint(20),createtime datetime);
INSERT INTO sp_tab1 Select ID,Nvc_content,I_objectID,I_tmID,createtime from space_operation_record where status<>0 and I_operationID=opsid and I_userID=userid ;
select count(*) from sp_tab1 into couid;
set @ihod = 0;
set @listp = '';
set @listpp = '';
set @content0p = '';
set @content0 = '';
while couid > 0 do
select ID,Nvc_content,I_obyuID,createtime,I_tID into @iok,@conuiy,@objiplk,@crtimhr,@tmids from sp_tab1 where ID > @ihod order by ID asc limit 0,1;
if @iok <> '' then
if mname = 'blog' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,tikk);
elseif mname = 'team' then
if(@identiftion = 'addblog' || @identiftion = 'mdyblog') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listpp = CONCAT(@listpp,CONCAT(@objiplk,','));
set @operarry1p = substring_index(@conuiy,'|',1);
set @operarry2p = substring_index(@conuiy,'|',-1);
set @content0p = CONCAT(@content0p,CONCAT(@operarry2p,SPACE(1)));
set @objlistp = substring(@listpp,1,length(@listpp)-1);
end if;
elseif mname = 'space' then
if(@identiftion = 'headphoto' || @identiftion = 'status') then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,I_tmID,createtime) VALUES (@iok,userid,@conuiy,@crtimhr,@tmids,tikk);
else
set @listppr = CONCAT(@listppr,CONCAT(@objiplk,','));
set @operarry1pr = substring_index(@conuiy,'|',1);
set @operarry2pr = substring_index(@conuiy,'|',-1);
set @content0pr = CONCAT(@content0pr,CONCAT(@operarry2pr,SPACE(1)));
set @objlistpr = substring(@listppr,1,length(@listppr)-1);
end if;
else
set @listp = CONCAT(@listp,CONCAT(@objiplk,','));
set @operarry1 = substring_index(@conuiy,'|',1);
set @operarry2 = substring_index(@conuiy,'|',-1);
set @content0 = CONCAT(@content0,CONCAT(@operarry2,SPACE(1)));
set @objlist = substring(@listp,1,length(@listp)-1);
end if;
set @ihod = @iok;
end if;
set couid = couid -1;
end while;
if @content0 <> '' then
set @contentp = CONCAT(@operarry1,concat('|',@content0));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlist);
end if;
end if;
if @content0p <> '' then
if @identiftion = 'addphoto' then
set @contentp = CONCAT(@operarry1p,CONCAT('|',@content0p));
else
set @contentp = CONCAT(@operarry1p,CONCAT(@content0p,'|'));
end if;
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
if @content0pr <> '' then
set @contentp = CONCAT(@operarry1p,concat('|',@content0pr));
Select createtime,ID into @uitimej,@IDjok from space_operation_record where status<>0 and I_operationID=opsid order by createtime desc limit 0,1;
if @uitimej <> '' then
INSERT INTO space_operation_stat(I_operationID,I_userID,Nvc_content,D_stattime,createtime,Nvc_objlist,I_tmID) VALUES(@iok,userid,@contentp,@crtimhr,tikk,@objlistp,@tmids);
end if;
end if;
delete from sp_tab1;
end if;
end if;
until done end repeat;
close c1;
drop temporary table if exists sp_tab1 ;
UPDATE space_operation_play SET status=0;
UPDATE space_operation_display SET status=0;
Select createtime into @ptimes from space_operation_stat where status<>0 order by createtime desc limit 0,1;
if @ptimes <>'' then
create temporary table if not exists sp_tab2(id bigint(20),Nvc_content MEDIUMTEXT,I_userID bigint(20),I_lyuID bigint(20),D_stattime datetime);
INSERT INTO sp_tab2 Select ID,Nvc_content,I_userID,I_tmID,D_stattime from space_operation_stat where status<>0 and createtime=@ptimes order by D_stattime desc limit 0,30;
select count(*) from sp_tab2 into @cou1id;
set @uoj = 0;
while @cou1id > 0 do
select ID,Nvc_content,I_userID,D_stattime,I_lyuID into @io1k,@conui1y,@objipl1k,@crtimh1r,@unlpa from sp_tab2 where ID > @uoj order by ID asc limit 0,1;
if @io1k <> '' then
INSERT INTO space_operation_play(I_statID,Nvc_content,D_stattime,I_userID,Createtime,I_tmID) VALUES (@io1k,@conui1y,@crtimh1r,@objipl1k,now(),@unlpa);
set @uoj = @io1k;
end if;
set @cou1id = @cou1id -1;
end while;
drop temporary table if exists sp_tab2 ;
end if;
end
E. mysql的表結構和數據都存儲在哪些物理文件裡面
一般是查看配置文件my.ini看看datadir 其次,在客戶端可以用 show variables like 'datadir'查看
F. 如何導出mysql資料庫表結構
項目開發中經常會用到mysql資料庫,免不了要導出表數據或者表結構
打開SQLyog客戶端工具連接資料庫,輸入用戶名和密碼,點擊connection按鈕
2
打開要導出的所在表的資料庫,例如我這里資料庫為e
3
游標聚焦表名字,然後右鍵-----》Export------>Backup Table As SQL Dump...
4
下圖紅色數字1 2 3 4 5一定 要注意,我來解釋一下,1,Structure only 意思是僅僅導出表結構,並不導出表數據 ,。2,Data only 僅僅導出表數據,。3,Structure and data 及導出表結構也導出表數據。,4,導出路徑。5,要導出的表
G. MySQL的用戶信息存儲在MySQL哪個資料庫的哪個表中
1、首先在電腦中,打開本地已經安裝的Navicat for MySQL,打開Navicat for MySQL工具軟體的主界面。
H. 怎樣在 MySQL 表中存儲樹形結構數據
一般比較普遍的就是四種方法:(具體見 SQL Anti-patterns這本書)
Adjacency List:每一條記錄存parent_id
Path Enumerations:每一條記錄存整個tree path經過的node枚舉
Nested Sets:每一條記錄存 nleft 和 nright
Closure Table:維護一個表,所有的tree path作為記錄進行保存。
I. 怎樣在 mysql 表中存儲圖形結構數據
圖片插入到資料庫不是個好方法,如果你確實要存儲圖片到資料庫的話,修改你的sql語句,不可以直接插入的。例如:
INSERT into person(p_id,p_name,p_sex,p_age) value("asdsadssdsadfff","addsdsa","dddd",113);
update person set p_image = LOAD_FILE('D:\incident1.jpg') where p_id = "asdsadssdsadfff";
建議把'D:\incident1.jpg'放在mysql的安裝目錄裡面,避免許可權問題。。。
解釋:sql必須要有對 'D:\incident1.jpg'文件 和相應的路徑 讀許可權,要不也不可以的。 另外檢查LOAD_FILE 函數是否被禁用。這個函數是個危險的函數,很容易利用該函數對資料庫攻擊。
LOAD_FILE(file_name):
讀取file_name文件 並以字元串形式返回,使用這個函數時,file_name必須存在於伺服器上,而且是完整路徑,sql要具有file_name的讀取許可權,還有該文件的size必須小於資料庫 max_allowed_packet的值,否則讀取的值為空。如果文件不存在或者sql沒有讀許可權,那麼該函數講返回null