Mac uses Homebrew to install redis, mysql and configure

Mac uses Homebrew to install redis, mysql

Install Homebrew

Homebrew is a software package management tool under the Mac OS platform, with many useful functions such as installation, uninstallation, update, viewing, and searching. A simple instruction can realize package management without you having to care about various dependencies and file paths, which is very convenient and fast.
Tip: If the system changes the sell type, it may cause the problem of brew command not found. For details, please refer to my previous article How to solve various problems after using zsh on mac

Install Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Verify installation

brew -v                  
Homebrew 2.4.13
Homebrew/homebrew-core (git revision 81b05; last commit 2020-08-23)
Homebrew/homebrew-cask (git revision 70c2bf; last commit 2020-08-23)

Basic use of Homebrew

brew install <packageName>
brew uninstall <packageName>
brew services start <packageName>
brew services stop <packageName>
#如安装 node
brew install node
#如卸装 node
brew uninstall node
#如开启redis服务
brew services start redis
#如停止redis服务
brew services stop redis

Install redis

After installing Homebrew, you will find that all the software packages are so easy to manage;

start installation

brew install redis
# 最后控制台出现,后证明安装成功
==> Summary
/usr/local/Cellar/redis/版本号

View the path and configuration file location after installing redis

  • The software installed by Homebrew will default to the path **/usr/local/Cellar/**
  • The redis configuration file redis.conf is stored in the **/usr/local/etc** path

Start redis

Method 1: The window is closed and redis is automatically closed, suitable for those that do not need to run in the background

redis-server /usr/local/etc/redis.conf

Method 2: The redis service will not stop when the window is closed

brew services start redis

redis configuration

1. Modify the way you like to use the terminal

cd /usr/local/ect/
vim redis.conf

2. For those who are not accustomed to using the interrupt vi command, you can directly right-click the Finder (visit) -> go to the folder -> enter /usr/local/ect/ to find redis.conf and edit it with a text editor

Modify operating mode

Redis is started in the foreground by default. Our actual development is to run as a daemon. Find daemonize no and modify it to yes

Modify the local area network to be accessible

Many times the redis we install will also be open to colleagues on other LANs to connect and modify

bind 127.0.0.1   成为  bind 0.0.0.0 

(If you specify a certain ip access, you can set the corresponding ip, pay attention to the production environment not to directly 0.0.0.0 will allow all ip connections)

Enable redis key expiration push

In the common development process, we often need to use redis key expiration message notification, such as unpaid order expiration, activity time expiration, etc., find

notify-keyspace-events Ex //注释打开

Install mysql8

start installation

Version 8.0.19 is installed on the blogger’s computer~ The following configurations are for this version, and the other lower versions may have configuration differences;

brew install mysql
#或指定版本号 如8.0.19
brew install [email protected]
#安装后查看Mysql版本
mysql -V        
mysql  Ver 8.0.19 for osx10.15 on x86_64 (Homebrew)

Start service

#启动
brew services start mysql
#重启
brew services restart mysql
#停止
brew services stop mysql

Log in to mysql and set the root password

The newly installed mysql through brew, the root user has no password by default, just press Enter when prompted to enter the password

mysql -u root -p
# 修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';

Set up external access

The configuration file is in /usr/local/etc/mysql.cnf. After opening it through the terminal or Finder, you will see the following configuration, just change 127.0.0.1 to 0.0.0.0

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0 

So far, through this article, I have introduced you to the installation of some of our commonly used tools by Homebrew. I believe you will love this tool, such as: git, node, etc., can be installed directly using the brew install command~