Coder Social home page Coder Social logo

如何切换数据库到mysql about liteblog HOT 22 CLOSED

jicg avatar jicg commented on May 18, 2024
如何切换数据库到mysql

from liteblog.

Comments (22)

jicg avatar jicg commented on May 18, 2024

HI,你好。使用最新的版本,添加这两个环境变量到系统中 ,即可切换到mysql
liteblog_db_type = mysql
liteblog_db_url = user:pwd@tcp(address:port)/dbname?parseTime=true

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

我将本项目中引用都改成了项目的引用,不在使用github的引用路径(例如"liteblog/models"),结果登陆、访问的时候都提示非法访问,这个是什么情况

from liteblog.

jicg avatar jicg commented on May 18, 2024

你看下,要确保 views目录和static目录 一定要在运行目录下。

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

2018/10/17 10:45:56.649 [main.go:768] [ORM] sqlE:/GOPATH/src/qomo/models/core.go:50179msSELECT count(*) FROMusers WHEREusers.deleted_atIS NULL[] 0 2018/10/17 10:45:56.688 [I] [router.go:269] E:\GOPATH\src\qomo\controllers no changed 2018/10/17 10:45:56.689 [I] [router.go:269] E:\GOPATH\src\qomo\controllers no changed 2018/10/17 10:45:56.690 [I] [router.go:269] E:\GOPATH\src\qomo\controllers no changed 2018/10/17 10:45:56.690 [I] [router.go:269] E:\GOPATH\src\qomo\controllers no changed 2018/10/17 10:45:56.692 [I] [router.go:269] E:\GOPATH\src\qomo\controllers no changed 2018/10/17 10:45:57.149 [I] [asm_amd64.s:2361] http server Running on http://:8080 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] the request url is / 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] Handler crashed with error runtime error: invalid memory address or nil pointer dereference 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] C:/Go/src/runtime/asm_amd64.s:573 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] C:/Go/src/runtime/panic.go:502 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] C:/Go/src/runtime/panic.go:63 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] C:/Go/src/runtime/signal_windows.go:167 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] E:/GOPATH/src/github.com/jinzhu/gorm/main.go:743 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] E:/GOPATH/src/github.com/jinzhu/gorm/main.go:463 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] E:/GOPATH/src/qomo/models/note.go:37 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] E:/GOPATH/src/qomo/controllers/index.go:20 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] C:/Go/src/runtime/asm_amd64.s:573 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] C:/Go/src/reflect/value.go:447 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] C:/Go/src/reflect/value.go:308 2018/10/17 10:48:50.822 [C] [asm_amd64.s:573] E:/GOPATH/src/github.com/astaxie/beego/router.go:847 2018/10/17 10:48:50.823 [C] [asm_amd64.s:573] C:/Go/src/net/http/server.go:2694 2018/10/17 10:48:50.823 [C] [asm_amd64.s:573] C:/Go/src/net/http/server.go:1830 2018/10/17 10:48:50.823 [C] [asm_amd64.s:573] C:/Go/src/runtime/asm_amd64.s:2361
修改数据库为mysql,项目内部引用改为自己的,不引用github的路径,结果抱着个错误,网页端也提示
qomo:runtime error: invalid memory address or nil pointer dereference
请问这是什么问题啊

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

问题出在 index.go中的Get()方法中的
if ns, _ := c.Dao.QueryNotesByPage(page, limit, title); ns != nil { c.Data["notes"] = ns }
的查询

from liteblog.

jicg avatar jicg commented on May 18, 2024

可能mysql数据库没有初始化成功。你试下sqlite3是否能正常

from liteblog.

jicg avatar jicg commented on May 18, 2024

这两处代码,你也改了没?
这两处代码,你也改了没?

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

这两处也改了

from liteblog.

jicg avatar jicg commented on May 18, 2024

改下上面错误的那段代码,然后看下日志 。

原来的代码:

if ns, _ := c.Dao.QueryNotesByPage(page, limit, title); ns != nil { c.Data["notes"] = ns }{
    c.Data["notes"] = ns
}

改成下面的代码

        if c.Dao==nil{
		c.Abort500(errors.New("数据库初始化失败!"))
	}
        ns, err := c.Dao.QueryNotesByPage(page, limit, title)
	if err != nil {
		c.Abort500(err)
	}
	if ns != nil {
		c.Data["notes"] = ns
	}

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

errors 是引用哪个包的,直接替换,这个errors报错

from liteblog.

jicg avatar jicg commented on May 18, 2024

import 里面加上"errors",golang自带的sdk

import(
    ...
    "errors"
)

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] the request url is / 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] Handler crashed with error runtime error: invalid memory address or nil pointer dereference 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/runtime/asm_amd64.s:573 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/runtime/panic.go:502 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/runtime/panic.go:63 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/runtime/signal_windows.go:167 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] E:/GOPATH/src/github.com/jinzhu/gorm/main.go:743 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] E:/GOPATH/src/github.com/jinzhu/gorm/main.go:463 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] E:/GOPATH/src/qomo/models/note.go:37 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] E:/GOPATH/src/qomo/controllers/index.go:24 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/runtime/asm_amd64.s:573 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/reflect/value.go:447 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/reflect/value.go:308 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] E:/GOPATH/src/github.com/astaxie/beego/router.go:847 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/net/http/server.go:2694 2018/10/17 18:06:33.976 [C] [asm_amd64.s:573] C:/Go/src/net/http/server.go:1830 2018/10/17 18:06:33.977 [C] [asm_amd64.s:573] C:/Go/src/runtime/asm_amd64.s:2361 2018/10/17 18:06:33.977 [server.go:2921] [HTTP] http: multiple response.WriteHeader calls
这是新的错误

from liteblog.

jicg avatar jicg commented on May 18, 2024

错误的那段代码是,哪句?

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

note.go文件中
func (db *DB) QueryNotesByPage(page, limit int, title string) (note []*Note, err error) { return note, db.db.Model(&Note{}).Where("title like ?", fmt.Sprintf("%%%s%%", title)).Offset((page - 1) * limit).Limit(limit).Order("updated_at DESC").Find(&note).Error }

from liteblog.

jicg avatar jicg commented on May 18, 2024

路径都改全了吧? 尤其是 controllers->base.go .

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

亲,这是什么原因啊,我不明白,为什么要使用github全路径

from liteblog.

jicg avatar jicg commented on May 18, 2024

我试过,我的电脑没有问题。。。可以替换。应该还是你哪儿设置的问题

from liteblog.

jicg avatar jicg commented on May 18, 2024

方便的话,能否将你的代码发给我看下。http://xianyan.hellowcloud.com/note/new,用新增文章的附件功能上传下你的代码。

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

我的项目的地址https://gitee.com/idart/qomo,你下载下来看看

from liteblog.

jicg avatar jicg commented on May 18, 2024

此处写错了!
image

from liteblog.

jicg avatar jicg commented on May 18, 2024

我在 码云上rp了,你看下

from liteblog.

52lemon avatar 52lemon commented on May 18, 2024

好的,太谢谢你啦!!

from liteblog.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.