There may be some problems installing the mysql database on a mac system, especially for users who are not familiar with the command line. However, if you follow the steps below, you will have your mysql database installed and started on your mac in no time.
Step 1: Download MySQL
Go to the official website of MySQL (https://dev.mysql.com/downloads/mysql/) and download the latest mysql version. Select "MySQL Community Server" and select your operating system. In the "Select Operating System" drop-down box, select Mac OS X, then select your system version in the "Select OS Version" drop-down box. Next, you'll see a "Download" button on the page. Click to download the latest version of mysql.
Step 2: Install MySQL
Double-click the downloaded MySQL installation package to install, and then follow the prompts to complete the installation process. After completing the installation, you will see important files such as the mysql directory and configuration files.
Step 3: Set environment variables
On Mac, you need to add mysql's bin directory to the PATH environment variable so that you can access the mysql command directly in the terminal window.
Enter the following command in the terminal window to add the bin directory of mysql to the PATH environment variable:
export PATH=${PATH}:/usr/local/mysql/bin
If you want to automatically enable this variable every time the terminal window starts, you need to Add the above command to your shell configuration file. The most popular shell is bash, so open the ~/.bash_profile file, either using vim or nano, and append the above commands to the end of the file.
Step 4: Start MySQL
Enter the following command in the terminal to start the mysql service:
sudo mysql.server start
With this command, you will start the MySQL service. You can use the following command to check whether mysql has started:
ps -ef | grep mysqld
If you see mysqld in the process list, it means that mysql has started successfully.
Step 5: Create a database
To create a database, you need to log in to mysql with root privileges. This process requires you to enter the root username and password of mysql. Enter the following command in the terminal:
mysql -u root -p
Then enter the root password in the prompt that appears so that you can log in to mysql.
Next, you can create a new database as follows:
CREATE DATABASE mydatabase;
This will create a new database named "mydatabase" in mysql.
Step 6: Test the connection
To test the connection, you can connect to mysql using the following command:
mysql -u root -p mydatabase
You should be connected to the MYSQL server and can run at the mysql prompt Execute any mysql command.
Finally, to stop the mysql service, just enter the following command in the terminal window:
sudo mysql.server stop
If your system does not allow you to use sudo before the command, you can use the following command:
sudo chmod +x /usr/local/mysql/support-files/mysql.server sudo /usr/local/mysql/support-files/mysql.server start
This is done by giving mysql.server execution permissions and then starting the service.
Summary
The above are the main steps to install the mysql database under mac system. If you follow the steps above, you can install mysql database on mac in no time even if you are not familiar with command line tools.
The above is the detailed content of How to install mysql on mac. For more information, please follow other related articles on the PHP Chinese website!