1. Open the Terminal application on your Mac.
2. Update Homebrew by running the command: brew update
3. Install MySQL by running the command: brew install mysql
4. Start the MySQL server by running the command: mysql.server start
5. Secure the MySQL installation by running the command: mysql_secure_installation
6. Log in to the MySQL server by running the command: mysql -u root -p
7. Create a new database by running the command: CREATE DATABASE database_name;
8. Exit the MySQL server by running the command: exit
Installing MySQL using terminal on Mac; In this tutorial, you will learn how to download, install and secure MySQL on Mac using Brew via terminal.
How to Install MySQL on Mac using Brew
By using the following steps, you can install MySQL on Mac using Brew with terminal:
- Step 1: Install Brew
- Step 2: Install MySQL
- Step 3: Start MySQL
- Step 4: Secure MySQL
- Step 5: Connect to MySQL
Step 1: Install Brew
If you don’t have installed Homebrew on your Mac, so open your terminal or command line and execute the following command into it to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install MySQL
Now, execute the following command on the terminal to install MySQL on Mac using Brew:
brew install mysql
This command will download and install the latest version of MySQL on your Mac.
Step 3: Start MySQL
Once you have installed mysql by using the above command, then you need to start MySQL. So execute the following command on the terminal or command line to start MySQL:
mysql.server start
Step 4: Secure MySQL
By default, MySQL is not secure, and anyone with access to your Mac can access the database. Therefore, it is important to secure your MySQL installation.
Execute the following command on the terminal or command line to secure MySQL:
mysql_secure_installation
This command will open a prompt on the terminal to set a root password, remove anonymous users, disallow remote root login, and remove test databases.
Step 5: Connect to MySQL
Execute the following command on the terminal or command line to connect to MySQL:
mysql -u root -p
This will prompt you to enter the password you set for your MySQL root user. Once you enter the password, you will be connected to the MySQL server.
Conclusion
That’s it; In this tutorial, you learned how to download, install, and secure MySQL on Mac using Homebrew Terminal. The process is simple and can be completed within a few minutes. Once you’ve installed MySQL, it’s important to secure it by setting a strong root password and removing any unnecessary users and databases. With MySQL installed, you can start organizing and managing your data efficiently.