Can I use mysql queries to replace query_posts()?

It’s not clear what do you mean by template “accepting” variables.

WP_Query (which query_posts()/get_posts() are build on top of) is very flexible. In many cases it’s not as much being able to do something with it, as having experience using it to achieve results.

Typically even when queries cannot be expressed in single set of arguments, it is still very possible to make “compound” queries, by querying partial post sets and further using them in additional queries.

That said it is quite possible to use raw SQL. As long as you retrieve records from posts table accurately, you can instance WP_Post objects from them. Note that this will skip much of related WP functionality, such as caching, etc.