No, you can’t use any Mastercard credit card at Costco. Costco only accepts cards on the Visa network. But that’s a relatively new development. Costco was Amex-exclusive from 1999 until 2016, when they switched to Visa. Before 1999, they only took Discover cards. I don’t think Mastercard has ever been an option, though.
So if you only have a Mastercard and want to shop at Costco, you have a couple choices. For starters, you can still pay for Costco items with cash or a check. But do you really want to carry all that cash, take the time to write out a check or miss out on a lot of rewards?
Your best bet is to simply get a Visa credit card. There are lots of really rewarding offers out there, including the Costco Anywhere Visa Card by Citi. You need excellent credit to get it, but you get 4% cash back on gas, 3% on dining and travel, 2% at Costco and 1% on everything else.
Chase Freedom Unlimited and Capital One Quicksilver Visa cards are good choices too.