Graphic tutorial on installing MySQL database and configuring environment variables on Mac

Graphic tutorial on installing MySQL database and configuring environment variables on Mac

Install mysql

Download mysql. I downloaded: mysql-8.0.11-macos10.13-x86_64.dmg

Double-click to open mysql-8.0.11-macos10.13-x86_64.dmg, and then double-click mysql-8.0.11-macos10.13-x86_64.pkg

Just click on Continue, it's a fool-proof installation, nothing to say

Select "Use Legacy Password Encryption" here, otherwise when you use Navicat to connect to MySQL, you will get an error that the authentication cannot be loaded.

Set a password for the "root" user

Installation Complete

After successful installation, using the mysql command returns the error: command not found, because the environment variables have not been configured.

Configuring environment variables

First, you need to know what kind of Shell you are using on Mac OS X.

Open the terminal and enter: echo $SHELL Press Enter to execute

If the output is: csh or tcsh, then you are using C Shell.

If the output reads: bash, sh, zsh, then you are probably using a variant of the Bourne Shell.

The default shell for Mac OS X prior to 10.2 was C Shell.

The default shell for Mac OS X 10.3 and later is Bourne Shell.

Mine is bash:


Input: cd /usr/local/mysql, press Enter to execute

Then enter: sudo vim .bash_profile and press Enter to execute

You need to enter the root user password. Sudo is used by the root user to modify the environment variable file.

After entering the editor, we first press "i" to switch to the "insert" state. You can edit the content by moving the cursor up, down, left, or right, or by pressing space, backspace, and enter, just like in WINDOWS.

At the bottom of the document, enter: export PATH=${PATH}:/usr/local/mysql/bin

Then press Esc to exit the insert state, and enter :wq at the bottom to save and exit (or directly press shift+zz, or switch to uppercase mode and press ZZ to save and exit).

Input: source .bash_profile and press Enter to execute and run the environment variables.

Then enter the mysql command to use it.

If you cannot connect to MySQL using Navicat,

It probably means that the authentication plugin 'caching_sha2_password' cannot be loaded

solve

  • Open System Preferences, find MySQL, and click Initialize Database.
  • Enter your new password.
  • Select 'Use legacy password'.
  • Restart the mysql service.
  • Navicat links can now be used

After testing, I found that the above method requires re-source .bash_profile every time the terminal is closed and reopened.

PS: The following test is still invalid and has not been resolved yet

Some articles say vi ~/.zshrc, add it here:

export PATH=${PATH}:/usr/local/mysql/bin

After saving, source ~/.zshrc and you can do it once and for all.

Some articles mention modifying ~/.bashrc. If the system is zsh, modifying bashrc is invalid.

This is the end of this graphic tutorial on how to install MySQL database on Mac and configure environment variables. For more information about installing MySQL database on Mac and configuring it, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • [Project layout configuration] Nosql and Python Web-Flask framework combination
  • MySQL 1130 exception, unable to log in remotely solution
  • Solve the problem of garbled data in MySQL database migration
  • SQL Writing - Row Comparison
  • Solution to MySQL connection exception and error 10061
  • Solve the problem that the SpringBoot application.yaml file configuration schema cannot execute SQL
  • SQL IDENTITY_INSERT case study
  • Hotel Management System Designed and Implemented Based on JavaSwing

<<:  Improvement experience and sharing of 163 mailbox login box interactive design

>>:  Solution to Vue3.0 error Cannot find module'worker_threads'

Recommend

How to use vw+rem for mobile layout

Are you still using rem flexible layout? Does it ...

React implementation example using Amap (react-amap)

The PC version of React was refactored to use Ama...

How to wrap HTML title attribute

When I was writing a program a few days ago, I wan...

Detailed analysis of several situations in which MySQL indexes fail

1. Leading fuzzy query cannot use index (like ...

Integration practice of Vue+Element background management framework

Table of contents Vue+ElementUI background manage...

JavaScript implements simple calculator function

This article example shares the specific code of ...

960 Grid System Basic Principles and Usage

Of course, there are many people who hold the oppo...

Linux automatically deletes logs and example commands from n days ago

1. Delete file command: find the corresponding di...

jQuery implements simple button color change

In HTML and CSS, we want to set the color of a bu...

Markup Language - Phrase Elements

Click here to return to the 123WORDPRESS.COM HTML ...

Explanation of the configuration and use of MySQL storage engine InnoDB

MyISAM and InnoDB are the most common storage eng...

How to verify whether MySQL is installed successfully

After MySQL is installed, you can verify whether ...