How can Mega 2560 use the Wifi library of Arduino file?

We want to connect MySQL by wifi. There is a wifi library in Arduino file, I also found a MySQL library which based on the wifi library from github.com, but my leader only gave me a Mega 2560 without wifi compenent. In my opinion, even though I connect our wifi compenent (ESP8266) to serial of Mega 2560, I only can write data to serial, rather than use Arduino wifi libarary and that MySQL library directely.

Can I update my Mega 2560 to use Arduino wifi libarary?
if not, is there the Arduino libarary for ESP8266 or other wifi compenent which I can buy?

(Write whole code without any library is a little hard for me , a new user,haha)

Can I update my Mega 2560 to use Arduino wifi libarary?

Yes, buy a WiFi shield.

if not, is there the Arduino libarary for ESP8266 or other wifi compenent which I can buy?

What firmware is on that ESP8266? Libraries to be used with a ESP8266 on a Mega2560 depends on the firmware on the WiFi processor and how it's connected to the Mega.

pylon:
Yes, buy a WiFi shield.

It means that after I can connect my mega 2560 and this wifi shield, I can use the wifi library of Arduino? it is good!
I am not familar with arduino, can you give me a link for buying a cheap wifi shield?

have a look at

look on ebay for ESP-01 devices

I have used the ESP-01 to communicate with web servers using HTTP POST and GET
this example is for ethernet but is easy to adapt to WiFi

It means that after I can connect my mega 2560 and this wifi shield, I can use the wifi library of Arduino?

It might help to provide a link to that MySQL library you're planning to use as there are several WiFi libraries for the Arduino and we have to know which one you're referring to.