gpt4 book ai didi

mysql - 将多行mysql字符串转换为预定义的csv格式?

转载 作者:行者123 更新时间:2023-11-29 13:36:04 28 4
gpt4 key购买 nike

这更像是关于 csv、excel、mysql 文件的操作方法问题,而不是标准编码问题。不过,我真的很感谢对此的一些帮助。

我有这个预定义的 CSV 格式,我需要它才能使用 Sequel Pro 将其导入数据库。

ID,"user_login","user_pass","user_nicename","user_email","user_url","user_registered","user_activation_key",user_status,"display_name"

1,"some_name","$P$BDMmGci3KAqNQwfPtgzfQTp8D3k7bC.","some_name","some.name@gmx.net","","2013-06-27 11:32:08","",0,"Some Name"
<小时/>

另一方面,我有一个旧的数据库文件,如下所示......

CREATE TABLE `ezxsubscription` (                                
`id` int(11) NOT NULL auto_increment,
`version_status` int(11) NOT NULL default '0',
`subscriptionlist_id` int(11) default '0',
`email` varchar(255) default '',
`hash` varchar(255) default '',
`status` int(11) default '0',
`vip` int(11) default '0',
`last_active` int(11) NOT NULL default '0',
`output_format` varchar(255) default '',
`creator_id` int(11) NOT NULL default '0',
`created` int(11) NOT NULL default '0',
`confirmed` int(11) NOT NULL default '0',
`approved` int(11) NOT NULL default '0',
`removed` int(11) NOT NULL default '0',
`user_id` int(11) default '0',
`bounce_count` int(11) default '0',
PRIMARY KEY (`id`,`version_status`)
) TYPE=MyISAM;

--
-- Dumping data for table `ezxsubscription`
--

INSERT INTO `ezxsubscription` VALUES (454,1,5,'name@surname.com','31b6bde64e1282ba82d7d0c8ad6ebaa9',2,0,0,'2',1127,1142840848,0,1142840868,0,2633,0);
INSERT INTO `ezxsubscription` VALUES (1,1,5,'name.name@gmail.com','fff4b8d75ecdfad43ed8c89444939cfb',2,0,0,'2',10,1141956489,1141956489,1141956489,0,14,0);

数据库中有大约 400 个用户,我无法手动排序。我需要使数据库文件采用上面预定义的 CSV 格式。其中电子邮件地址应为 user_loginuser_name。旧数据库的其余部分,例如approvedremoved或其他内容都可以简单地忽略。 这只是关于用户登录名和密码。

关于如何做到这一点有什么聪明的想法吗?目的是将旧数据库的所有老用户导入到新数据库(基于Wordpress)。

我真的很感激一些提示或技巧。

提前谢谢您。马特

<小时/>

更新:

这是 ezxsubscription 表的旧格式。

"id","version_status","subscriptionlist_id","email","hash","status","vip","last_active","output_format","creator_id","created","confirmed","approved","removed","user_id","bounce_count"
1,1,5,"andreas@gmail.at","fff4b8d75ecdfad43ed8c89444939cfb",2,0,0,2,10,1141956489,1141956489,1141956489,0,14,0

我现在想做的就是将此用户转换为新的 WordPress 格式:

"ID","user_login","user_pass","user_nicename","user_email","user_url","user_registered","user_activation_key","user_status","display_name"
1,"local","$P$BCf7QHr3rsp0YNZd7eMfYgncRZmR6j0","local","temp@local.dev","","2013-03-14 18:46:29","",0,"local"

我什至无法理解旧数据库中的哈希的含义。我想做的就是将所有现有的旧用户复制到新的 WordPress 数据库,以便我拥有电子邮件地址和密码,以便他们能够再次登录。

所以我想让旧电子邮件成为新 WordPress 数据库的用户名。 hash 可能应该是 WordPress 中新的 user_pass 。不过,我只希望哈希是当前登录的密码 - 我什至不确定。

亲切的问候,马特

最佳答案

使用SELECT ... INTO OUTFILE使用这样的查询从旧表创建 CSV 文件的语法

SELECT *
INTO OUTFILE '/path/to/your/file.csv'
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM
(
SELECT 'id', 'user_login', 'user_pass', 'user_nicename','user_email','user_url','user_registered','user_activation_key','user_status','display_name'
UNION ALL
SELECT id, email, hash, SUBSTRING_INDEX(email, '@', 1), email, '', created, '', status, SUBSTRING_INDEX(email, '@', 1)
FROM ezxsubscription
) q

创建的文件内容:

"id","user_login","user_pass","user_nicename","user_email","user_url","user_registered","user_activation_key","user_status","display_name""454","name@surname.com","31b6bde64e1282ba82d7d0c8ad6ebaa9","name","name@surname.com","","1142840848","","2","name""1","name.name@gmail.com","fff4b8d75ecdfad43ed8c89444939cfb","name.name","name.name@gmail.com","","1141956489","","2","name.name"

关于mysql - 将多行mysql字符串转换为预定义的csv格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18734367/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com