Skip to main content

Database Configuration

Once your database content is ready, you can configure the database in your configuration file by adding the following content:

manifest/config/config.yaml

database:
type: "mysql"
host: "127.0.0.1"
port: "3306"
user: "root"
pass: "root"
name: "goframe"
timezone: "Asia/Shanghai"
debug: true
  • type: Type of the database, such as mysql/sqlite/pgsql/oracle, etc.
  • host: Database host.
  • port: Database port.
  • user: Database connection username.
  • pass: Database connection password.
  • name: Name of the database to connect to.
  • timezone: Database timezone, set to Asia/Shanghai or Local. Not setting this correctly can lead to time conversion issues.
  • debug: Whether to enable debug mode. Enable during learning and development phases to view database operation-related output.

The above is the simplest configuration for connecting to a database. For more complex configurations, refer to the official documentation ORM Configuration.

The above configuration can be simplified using a link format: type:user:password@tcp(host:port)/dbname?param1=value1&..

database:
debug: true
link: "mysql:root:root@tcp(127.0.0.1:3306)/goframe?loc=Local&parseTime=true"

Alternatively, you can retain the previous configuration format:

database:
type: "mysql"
host: "127.0.0.1"
port: "3306"
user: "root"
pass: "root"
name: "goframe"
timezone: "Local"
debug: true
link: "mysql:root:root@tcp(127.0.0.1:3306)/goframe?loc=Local&parseTime=true"

Using the link format ensures that the other individual configurations will not take effect.