database

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

==============================================

出了一个问题, 今天早上从正式环境下下载sql文件,

然后导入到本地环境,却怎么也不生效, 这个是什么问题呢, 原来是因为导错了文件,

为什么会出现这个问题呢,我不知道, 可能是因为文件太多了, 是因为下载目的文件夹里面有很多类似的文件,

然后我直接选择了高亮的那一个,  但选择的这个是错的。

 

==============================================

 

其实都操作很多遍了, 似乎都没有记录, 做过就忘了,这个就很尴尬了。记个笔记,再说

导出mysql数据库文件,
不用登录mysql情况下, 但确定能访问到mysql, 在目标文件夹下运行 mysqldump -uroot -p database_name > ./FILE_NAME.sql
1, mysqldump是一个命令, 同mysql是同一个级别的
2, > 后面要加上文件名, 不能加多个文件夹, 比如把文件放到新建的文件夹下, 这样是不行的, 因为mysqldump没有权限来创建文件夹, 或者他根本不想创建文件夹, 如果碰到不能识别的文件夹路径, 就直接报错, 所以要自己指定已有文件夹下的文件名

 

导入数据库文件, 据说有两种方法, 有的人用这个方法, 有的人用那个方法
1, 进入mysql之后, 就用 use DATABASE_NAME; source ./FILE_NAME.sql 就可以导入了
2, mysql -u USER -p DATABASE_NAME < PATH/TO/FILE.sql
这个命令有点邪门, 按道理,应该是mysqlimport 之类的, 但不是, 
那么 mysqlimport和表是强绑定的, 用的不多。

 

===================================================

我直接在src controller里面file_put_contents()
就会在根目录生成一个abc.txt的文件
---
如果只是一个文件的内容,那么放在本地文件夹下应该会更好一点,
---
As a general rule, databases are slower than files
--

If you want to load the full-content of a file to a PHP variable, the easiest (and, probably fastest) way would be file_get_contents.

But, if you are working with big files, loading the whole file into memory might not be such a good idea : you'll probably end up with a memory_limit error, as PHP will not allow your script to use more than (usually) a couple mega-bytes of memory.


So, even if it's not the fastest solution, reading the file line by line (fopen+fgets+fclose), and working with those lines on the fly, without loading the whole file into memory, might be necessary...

---

posted @ 2018-03-22 09:36  qqisnow2021  阅读(207)  评论(0编辑  收藏  举报