I am writing a c++ program that will store everything in a mysql database. I would like to avoid the Windows Security window from popping up and asking if mysqld can have priviledges. If I click cancel (in response to the firewall window), the program still runs just fine because everything is local.
I am trying to use named pipes with the –skip-networking flag to avoid this firewall window.
START EDIT:
I am using a portable version of mysqld. It won’t have admin priviledges. (Thanks to Ben for pointing out that this is an important piece of information)
END EDIT
I am using the following command to start the mysqld server:
C:\tmp_report\12345\mysqld\mysql\bin\mysqld --user=root \
--basedir="C:\tmp_report\12345\mysqld\\mysql" \
--datadir="C:\tmp_report\12345\mysqld\data" \
--pid-file="C:\tmp_report\12345\mysqld\mysql.pid" \
--log-error="C:\tmp_report\12345\mysqld\mysql.err" \
--skip-networking \
--enable-named-pipe
This works and I am able to connect to the database using the following command line statement:
mysql --pipe -uroot
I am trying to connect through the c-api as follows:
unsigned int mysql_timeout=200;
unsigned int protocol=MYSQL_PROTOCOL_PIPE;
bool mysql_reconnect=true;
bool mysql_local_infile=true;
if (mysql_options(conn,MYSQL_OPT_CONNECT_TIMEOUT, (char *)&mysql_timeout)){*logstream<<"mysql option error connect_timeout";}
if (mysql_options(conn,MYSQL_OPT_READ_TIMEOUT, (char *)&mysql_timeout)){*logstream<<"mysql option error read_timeout";}
if (mysql_options(conn,MYSQL_OPT_WRITE_TIMEOUT, (char *)&mysql_timeout)){*logstream<<"mysql option error write_timeout";}
if (mysql_options(conn,MYSQL_OPT_RECONNECT, &mysql_reconnect)){*logstream<<"mysql option error reconnect";}
if (mysql_options(conn,MYSQL_OPT_LOCAL_INFILE, &mysql_local_infile)){*logstream <<"mysql option error local_infile";}
if (mysql_options(conn,MYSQL_OPT_NAMED_PIPE, NULL)){*logstream<<"mysql option error MYSQL_OPT_NAMED_PIPE";}
if (mysql_options(conn,MYSQL_OPT_PROTOCOL, (char *)&protocol)) {*logstream<<"mysql option error protocol";}
if (!mysql_real_connect(conn,
"localhost", // SERVER
"root", // USER
NULL, // PASS
NULL, // DATABASE
0, // port
NULL, // socket
0 // client_flag
)){
*logstream<<"Database::connect mysql_real_connect failed"<<endl;
*logstream<<mysql_error(conn)<<endl;
conn=NULL;
}
The result of this mysql_real_connect call is:
Database::connect mysql_real_connect failed
Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0
If I use the TCPIP connection, everything works fine except that the Windows firewall pops up. I would really like to make this work without requiring the user to click cancel on the firewall window.
Any help is greatly appriciated!
If MySQL is intentionally local only, you should simply configure it to listen only on the local address. Put this in your
my.cnffile:Otherwise use
netsh advfirewallor similar to configure the firewall to allow MySQL. This would generally be done when you install MySQL.Examples:
Or from script:
For a single-use installation which doesn’t have or require admin privileges, you can configure local communication using the nonroutable IP address and a random port.
You can achieve this by adding
--bind-address=127.0.0.1 --port=62190to the command line.You won’t be able to alter the firewall rules unless you are an administrator, and listening on named pipes generally requires administrative privileges too. Creating a shared memory section requires SeCreateGlobalPrivilege, so essentially the same restriction applies.