当前位置:首页 » 服务存储 » im消息存储到mysql表结构
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

im消息存储到mysql表结构

发布时间: 2022-05-30 17:50:32

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