Asterisk Realtime not working after MySQL upgrade to 5.7 version


Asterisk (version 11 & 13) Realtime was working fine with MySQL version 5.5 but when I upgraded MySQL 5.7. It stops working and following errors appeared:

ERROR[17524] res_config_mysql.c: MySQL RealTime: Failed to connect database server <database-name> on localhost (err 2003). Check debug for more info.
WARNING[17524] res_config_mysql.c: Table <table-name> not found in database.  This table should exist if you're using realtime.

There was no issue in config files, database and table but it happens after MySQL upgraded from 5.5 to 5.7 version.

Can anyone help me to fix this issue or I should downgrade MySQL to previous version?


MySQL no longer supports the old MySQL functions (ex. mysql_connect). You’ll need to change the driver to mysqli, PDO, or ODBC.


If you check res_config_mysql.c in Asterisk 11.17.1, 11.25.1 & 13.0.1 then it is using mysql_real_connect() function to connect database and it is supported in MySQL version 5.7 as this is the reference:

if (mysql_real_connect(&conn->handle, conn->host, conn->user, conn->pass, conn->name, conn->port, conn->sock, 0)) {
			/* The default is no longer to automatically reconnect on failure,
			 * (as of 5.0.3) so we have to set that option here. */
			mysql_options(&conn->handle, MYSQL_OPT_RECONNECT, &trueval);
			ast_debug(1, "MySQL RealTime: Successfully connected to database.\n");
			conn->connected = 1;
			conn->connect_time = time(NULL);
			return 1;
		} else {
			ast_log(LOG_ERROR, "MySQL RealTime: Failed to connect database server %s on %s (err %d). Check debug for more info.\n", conn->name, !ast_strlen_zero(conn->host) ? conn->host : conn->sock, mysql_errno(&conn->handle));
			ast_debug(1, "MySQL RealTime: Cannot Connect (%d): %s\n", mysql_errno(&conn->handle), mysql_error(&conn->handle));
			conn->connected = 0;
			conn->connect_time = 0;
			return 0;


My mistake. I was thinking about the PHP-MySQL functions. Ignore my earlier comment.