Answer the question
In order to leave comments, you need to log in
No connection to mysql golang database?
Can you tell me there is no connection to the mysql database
package main
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"database/sql"
)
func main() {
db, err := sql.Open("mysql", "root:[email protected](127.0.0.1:3306)/freeswitch")
//db, err := sql.Open("mysql","root:[email protected](/var/run/mysqld/mysqld.sock)/freeswitch")
if err != nil {
panic(err) ///если коннекта к БД нет кидаюю панику
}
if err != nil {fmt.Println("Коннект к БД есть ")} else {fmt.Println("Коннекта к БД нет")}
db.Close()///закрываю коннект
}
[[email protected] scripts]# mysql -pqld501a87f54 -uroot -h127.0.0.1
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3600
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> Bye
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question