简体   繁体   English

如何从外部mysql数据库将数据导入Symfony2项目?

[英]How to import data from external mysql db into a Symfony2 Project?

I'm developping a new version of my website with Symfony2. 我正在使用Symfony2开发网站的新版本。 I used mysql on the previous version and now I use Doctrine2/Mysql. 我在以前的版本上使用mysql,现在使用Doctrine2 / Mysql。 I want to import my User Table into the new version. 我想将用户表导入新版本。 I think that the best way is to use the command tool provided by Symfony2. 我认为最好的方法是使用Symfony2提供的命令工具。

However, I don't know how to browse my old mysql database (or mysql dump) in order to execute php script to populate my new database. 但是,我不知道如何浏览旧的mysql数据库(或mysql dump)以执行php脚本来填充新数据库。

Any ideas ? 有任何想法吗 ?

You don't need to have a new database, you can keep using the actual one. 您不需要新数据库,可以继续使用实际的数据库。 But if you ever want duplicate it, you can use the mysqladmin command tool . 但是,如果您想复制它,则可以使用mysqladmin命令工具
Then, you can generate your entities from your database . 然后,您可以从数据库中生成实体

Sounds tricky enough to be an ETL problem. 听起来很棘手,已经成为ETL问题。 There are a number of tools out there; 那里有很多工具 many enterprise though a few dual licensed open source. 许多企业虽然有一些双重许可的开源软件。 If you're only doing this once, then many of the tools may be overly complex. 如果只执行一次,那么许多工具可能会过于复杂。 If you have to do this kind of data munging often, however, then a good ETL app can be a huge time saver. 但是,如果您必须经常进行这种数据处理,那么好的ETL应用程序可以节省大量时间。 I can recommend Altova's MapForce as one of the more straightforward and intuitive. 我可以将Altova的MapForce推荐为更简单直观的工具之一。 It's Windows-only though. 不过,它仅适用于Windows。

I did it ! 我做的 !

I don't know if that is the best solution but it works. 我不知道这是否是最好的解决方案,但是它可行。

1) Import the old table in my new database 1)将旧表导入我的新数据库

2) Ask Doctrine to introspect the database and generate the corresponding metadata files. 2)要求Doctrine自省数据库并生成相应的元数据文件。

php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force

3) Ask Doctrine to import the schema and build related entity classes by executing the following command 3)通过执行以下命令,要求Doctrine导入架构并构建相关的实体类

php app/console doctrine:mapping:import AcmeBlogBundle annotation

Now, I can use this EntityManager on my old database to do all the scripts I want. 现在,我可以在旧数据库上使用此EntityManager来执行所需的所有脚本。

You can find more information here : http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html 您可以在这里找到更多信息: http : //symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM