Physically you use one port and one cable to connect to your main network and use the second port and a second cable to connect directly to the printer. The printer obviously needs to have an Ethernet interface itself.
You will however need to configure the second port on the Mac and the Ethernet port on the printer to each have manually configured TCP/IP addresses and these should be in a different network range to your main network.
If you main network is something like 192.168.1.1 then your printer and the port on the Mac connecting to it need to be in a different network e.g. 192.168.11.1.
In theory if the printer supports Bonjour aka. mDNS then you might be able to get away with not needing to configure TCP/IP addresses for that connection.
The main reasons for using a second separate connection like this would be either performance or security, and frankly I don't think either really apply here. It would mean no other computers on your main network will be able to access the printer.