从另一个 MyISAM 表自动加载 MEMORY 表
为了提高服务器性能,我决定使用内存表来更快地读取用户信息。
我的问题是:服务器关闭后如何从另一个 MyISAM 表自动加载 MEMORY 表?
每次我想在内存中查找时,我都可以检查行数,然后通过 PHP 脚本逐行加载,但从 MyISAM 读取 2,000,000 条记录并保存在内存中需要时间。并检查行数。尽管它不是线程安全的,我应该照顾它。
还有更好的办法吗?
To increase server performance, I decided to use memory table for faster reading user's info.
My question is: How to auto load MEMORY table from another MyISAM table after server shutdown?
I can check rows count every time I want to lookup in MEMORY and then, load row by row by a PHP script, but it takes time to read 2,000,000 records from MyISAM and save in MEMORY. and checking rows count. although it is not thread safe and I should take care of it.
Is there any better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是修改启动 MySQL 的任何脚本(mysqld_safe?)并让它运行“mysql”以发出命令来运行存储过程,该存储过程会填充您的表。我不相信 MySQL 内部有任何可以在启动时自动触发的东西,或者任何类型的内部作业调度程序。
Simplest would be to modify whatever script is starting MySQL (mysqld_safe?) and have it run 'mysql' to issue a command to run a stored proc which does your table populating. I don't believe MySQL has anything internally that you can trigger automatically at startup, or any kind of internal job scheduler.
我通过以下方式解决了这个问题。
1. 在 php 上创建一个脚本,并将其设置为 cron。
草稿版本:
//如有必要进行最终检查并发送邮件或其他通知
参考文献:
http://dev.mysql.com/doc/refman/5.0 /en/load-data.html
I have solved this problem in the following way.
1. Create a script on php which is set to cron.
Draft version:
//final checking if necessary and send mail or other notification
References:
http://dev.mysql.com/doc/refman/5.0/en/load-data.html
看来您还可以使用 init_file 选项将 MySQL 配置为在启动时自动运行某些语句:
http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_init-file
你可以告诉它运行一个文件填充您的内存表。
如果您需要偶尔更新内存表,另一个考虑因素是使用事件:
http://dev.mysql.com/doc/refman/5.6/en/create-event.html
It appears you can also configure MySQL to automatically run certain statements on startup using the init_file option:
http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_init-file
You could tell it to run a file that populates your memory table.
Another consideration, if you need to occasionally update your memory table is to use events:
http://dev.mysql.com/doc/refman/5.6/en/create-event.html