Construction of MySQL Environment under Mac

Keywords: MySQL brew Database Mac

It's easy to install MySQL under Mac. In summary, there are two ways to install MySQL.

Method 1: Installation with dmg mirror

1, installation

Official website Download the installation package of MySQL Mac version and install it in regular steps. The following tips will appear in the installation process:

2019-03-24T18:27:31.043133Z 1 [Note] A temporary password is generated for root@localhost: TdfRm19!o0Xi

TdfRm19! O0Xiis the initial password, it's best to remember first!

2. Landing

Login mysql at the terminal command line:

$ mysql -u root -p
# Enter the above password.

If this step prompts: bash: mysql: command not found, execute the following two commands to make a soft connection:

cd /usr/local/bin
ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql

3. Modifying Password

Prior to MySQL 8.0.4, you could execute SET PASSWORD=PASSWORD('new password'). But the new version can't be changed because the password authentication has changed. Specific steps can be referred to https://blog.csdn.net/yi247630676/article/details/80352655.

Method 2: Installation with Homebrew

As we all know, Mac can use homebrew for installation management, which is very convenient. If homebrew is not installed, you can click on it. https://brew.sh/ Installation.

Here's how mysql is installed

$ brew install mysql   # Install the specified version: brew install mysql@1.1.1

Next, just wait. We already know what we need to do when the following text appears.

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

Follow the instructions and proceed with the initialization operation:

$ myysql_secure_installation

There will be many problems in the initialization process. The following is the specific problem section, which is explained by the annotations.

Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y   ## Reply y Y y requires more than 8 bits of password, reply n is not restricted

The password validation component is not available. Proceeding with the further steps without the component.
Please set the password for root here.

New password:   ## Set your password

Re-enter new password:   ## Enter your password again

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    ## Whether to remove anonymous users. Considering safety, I chose y.
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   ## Is remote connection to mysql root allowed? I use it as a local debugger, not a remote server, so y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y      ## Whether y deleted the test database, I chose y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y      ## Select y to reload the permission list
Success.

All done!

Now that the configuration is over, let's start mysql and remember the following commands:

$ mysql -u root -p   ## Landing mysql
$ brew services start mysql@5.7   ## Start mysql
$ brew services stop mysql@5.7   ## Stop mysql
$ mysql.server start   ## Start MySQL (no background service)

Posted by AKalair on Sun, 24 Mar 2019 13:21:28 -0700