1、引用包
sqljocky5: ^2.2.1
2、在my.ini文件最后添加
[mysqld]
default_authentication_plugin=mysql_native_password
3、重启MySQL(百度)
4、然后新建用户,用新用户建数据库,然后就是代码:主机用10.0.2.2。
import 'dart:async';
// ignore: import_of_legacy_library_into_null_safe
import 'package:sqljocky5/sqljocky.dart';
init() async {
var s = ConnectionSettings(
user: "my",
password: "123456",
host: "10.0.2.2",
port: 3306,
db: "mydatabase",
);
var conn = await MySqlConnection.connect(s);
await conn.execute('CREATE TABLE people (id INTEGER NOT NULL auto_increment, '
'name VARCHAR(255), '
'age INTEGER, '
'PRIMARY KEY (id))');
}
5、点赞。