MacOS High Sierra Homebrew 安装 MySql Community Server 8.*

使用Mac Homebrew 安装MySQL流程

  1. Clear environment
    $ brew remove mysql
    $ brew cleanup
    $ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    $ rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    $ sudo rm -rf /usr/local/var/mysql

  2. install mysql
    check current available version: $ brew info mysql
    install: $ brew install mysql
    ==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.19.high_sierra.bo
    ==> Downloading from https://akamai.bintray.com/2f/2fe3b8b24f829746f145e7c6b0bc8
    ######################################################################## 100.0%
    ==> Pouring mysql-8.0.19.high_sierra.bottle.2.tar.gz
    ==> /usr/local/Cellar/mysql/8.0.19/bin/mysqld --initialize-insecure --user=lucky
    ==> Caveats
    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 -uroot

    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
    ==> Summary
    🍺 /usr/local/Cellar/mysql/8.0.19: 286 files, 291.2MB

    MySQL is installed under /usr/local/Cellar/mysql/8.. by default

    If you try to execute $ mysql_secure_installation, MAC may alerts below:
    Securing the MySQL server deployment.
    Enter password for user root:
    Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    This is because you haven’t start MySql.

  3. Setup environment:
    $ unset TMPDIR
    $ mysql_install_db --verbose --user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
    `

  4. Start MySQL Service by:
    $ brew services start mysql
    Expect output: ==> Successfully started mysql (label: homebrew.mxcl.mysql)

  5. config mysql root password
    $ mysql_secure_installation
    Securing the MySQL server deployment.
    Enter password for user root:

    VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component?
    Press y|Y for Yes, any other key for No: y
    The password validation component is not available. Proceeding with the further steps without the component.
    Using existing password for root.
    Change the password for root ? ((Press y|Y for Yes, any other key for No) :
    ... skipping.
    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) :
    ... skipping.
    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) :
    ... skipping.
    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) :
    ... skipping.
    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) :
    ... skipping.
    `* All done!``

  6. check MySQL service has been loaded:
    $ brew services list
    Name Status User Plist mysql started XXX /XXXLibrary/LaunchAgents/homebrew.mxcl.mysql.plist

  7. check MySQL version
    $ mysql -V
    Expected output : mysql Ver 8.0.19 for osx10.13 on x86_64 (Homebrew)

  8. login MySQL
    MacBook-Air:~ XXX$ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 29
    Server version: 8.0.18 MySQL Community Server - GPL
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    mysql> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | sys |
    +--------------------+
    4 rows in set (0.01 sec)

    mysql> use mysql
    Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql> show tables;

Common configuration:

  1. check mysql conf:
    mysql --help | grep cnf

Common Issues:

  1. “mysql command could not be found”
    Solved by execute export PATH=/usr/local/Cellar/mysql/<version>/bin/:$PATH in console
  2. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (61)
    Solution:
    You may miss step 3 in above guide

很棒!不过你这个标题怕大部分人都看不懂 :joy:
可以改个中文

1 个赞

用 Markdown 文档格式就更好了

离用mac安装mysql还差一个mac