Installing the MySQL command-line client on Mac can be done in multiple ways; I will primarily demonstrate using Homebrew as it is relatively straightforward and easy to manage.
- Install Homebrew If Homebrew is not already installed on your Mac, open Terminal and execute the following command to install it:
bash/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Homebrew is a package manager that simplifies the installation and management of software on your Mac.
- Install MySQL with Homebrew After installing Homebrew, run the following command in Terminal to install MySQL:
bashbrew install mysql
This command downloads and installs the latest version of the MySQL server along with its command-line client.
- Start the MySQL Service After installation with Homebrew, start the MySQL service using the following command:
bashbrew services start mysql
This leverages Homebrew's service management to launch the MySQL server.
- Secure Configuration of MySQL After the initial installation, it is recommended to run the security configuration script:
bashmysql_secure_installation
This script guides you through setting the root password, removing anonymous users, and disabling remote root access for security-related configurations.
- Connect to the MySQL Command-Line Client Once the MySQL service is running, connect to the MySQL server by executing the following command:
bashmysql -u root -p
-u root specifies logging in as the root user, and -p prompts you to enter the password.
By following these steps, you can successfully install and use the MySQL command-line client on your Mac, enabling convenient database management and operations.