mysql1_dart
mysql1_dart copied to clipboard
Unhandled Exception: SocketException: Connection refused / Connection timed out, host:
I am trying to send a single value to mysql DB but I am keep getting these errors. So first of all this is my code:
` var settings = new ConnectionSettings( host: 'localhost', port: 3306, user: 'flutter_admin', password: 'flutter_admin_password', db: 'romicp' );final conn = await MySqlConnection.connect(settings);
var result = await conn.query( 'insert into bluetoothvalues (taha) values (?)',
[3.66]);
print('Inserted row id=${result.insertId}');
} `
With this code, I get this error: Unhandled Exception: SocketException: Connection refused. So I was looking for solutions and i found out that this question was asked before and it was fixed by changing 'localhost' to ''10.0.2.2'' or your IPaddress. both ways gave me another error which is: Connection timed out, host:
Please anyone can help
class Mysql {
// Note: if you are using terminal base connection than localhost is 127.0.0.1
// Note if you are using fluter Emulator than localhost connection address is 10.0.2.2
static String host = '10.0.2.2',
user = 'root',
// Note:- I am not using any password in my database
// password = "123456789",
// Database name that i created inside mySQL (Which should already exited)
db = 'profiles';
// Note:- MySQL sever port
static int port = 8080;
Mysql();
Future<MySqlConnection> getConnection() async {
var settings = ConnectionSettings(
host: host,
port: port,
user: user,
// password: password,
db: db,
);
return await MySqlConnection.connect(settings);
}
}