码迷,mamicode.com
首页 > 数据库 > 详细

package.path require mysql 报错

时间:2015-03-10 11:49:04      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

在文件中

package.path = /usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;
package.cpath = /usr/local/lib/lua/5.1/?.so;

执行
local mysql = require "mysql" --正确
local mysql = require "resty.mysql" --报错

去掉
package.path = ‘/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;‘ 
package.cpath = ‘/usr/local/lib/lua/5.1/?.so;‘

local mysql = require "mysql" --报错
local mysql = require "resty.mysql" --正确


package.path 的默认路径指向哪的呢?

去掉 package.path,在页面中 随便引用一个不存在的模块 比如 require ‘aa‘

查看nginx错误日志返回

    no field package.preload[aa]
    no file /usr/local/openresty/lualib/aa.lua
    no file /usr/local/openresty/lualib/aa/init.lua
    no file ./aa.lua
    no file /usr/local/openresty/luajit/share/luajit-2.1.0-alpha/aa.lua
    no file /usr/local/share/lua/5.1/aa.lua
    no file /usr/local/share/lua/5.1/aa/init.lua
    no file /usr/local/openresty/luajit/share/lua/5.1/aa.lua
    no file /usr/local/openresty/luajit/share/lua/5.1/aa/init.lua
    no file /usr/local/openresty/lualib/aa.so
    no file ./aa.so
    no file /usr/local/lib/lua/5.1/aa.so
    no file /usr/local/openresty/luajit/lib/lua/5.1/aa.so
    no file /usr/local/lib/lua/5.1/loadall.so

发现  /usr/local/openresty/lualib/aa.lua 难道默认的路径是 /usr/local/openresty/lualib 于是在页面中加入

package.path = /usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;/usr/local/openresty/lualib/?.lua;

package.cpath = /usr/local/lib/lua/5.1/?.so;

执行正确

新手~~ 勿怪

 

package.path require mysql 报错

标签:

原文地址:http://www.cnblogs.com/wangxusummer/p/4325281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!