Home >Database >Mysql Tutorial >How to Connect to MySQL from the Command Line on a Mac?
Establishing a MySQL Command Line Connection
Connecting to MySQL from the command line on a Mac is essential for managing databases and performing data operations. This article will provide you with a step-by-step guide to connect to MySQL, showcasing the necessary code.
Procedure
Install MySQL Client: If you haven't already, install the MySQL client using the Homebrew package manager:
brew install mysql-client
Connect to MySQL: Establish a connection to the MySQL server using the mysql command along with your login credentials:
mysql -u <username> -p<password> -h <hostname or IP> <database name>
Example:
mysql -u myuser -pmypassword -h localhost mydatabase
Verify Connection: Upon successful login, you will see the MySQL prompt:
mysql>
Additional Notes
The above is the detailed content of How to Connect to MySQL from the Command Line on a Mac?. For more information, please follow other related articles on the PHP Chinese website!