This is the what I can visualise at the moment:
MySQL server is running, which is an application that listens on a port (something I'm not 100% clear on at the moment).
The server parses PHP code, part of which involves sending input to the MySQL server (which is a completely separate program via specific ports (code written in the mysqli class?),
which then returns output that the mysqli class interprets? and these messages are interpreted into errors, or an established connection, or a successful query, etc?
Is this a reasonably correct view of MySQL/PHP communication?
MySQL is a program which runs persistently in the background somewhere and manages data storage. It offers an interface to the outside world via a socket connection, on which it accepts SQL queries which prompt it to store new data or return existing data. To connect to this socket and send SQL queries over it, you need to speak a specific protocol that MySQL expects; it's just technical minutiae of how exactly to talk to MySQL over that socket. mysqli is one of the PHP libraries which can speak that protocol and thereby offers PHP code a method to talk to MySQL in SQL queries, abstracting the specifics of the socket protocol away. The mysql library (now old and deprecated) and PDO can do the same thing, they just "look" different on the PHP side (i.e. their PHP code interfaces are different from mysqli).
The (mostly) complete chain is: