0%

Mac杂谈

穷则独善其身,达则兼济天下。 —— 《孟子》之《尽心章句上》

一、常用命令

  1. 网络命令
    • nslookup
    • traceroute
    • hostname
    • ifconfig
    • arp
    • dig
    • sudo killall -HUP mDNSResponder
  • mail命令:

    mail命令是命令行的电子邮件发送和接收工具

  1. 直接通过命令mail -s "this is a title" 123123123@qq.com,回车输入邮件内容,control+d直接发送
  2. 使用管道命令echo hello | mail -s "this is a title" 123123123@qq.com
  3. 使用文件内容mail -s "some text" justin@51cto.com < ~/some.txt
  4. 使用三方服务smtp/msmtp,自行GG

二、常用免费软件

  1. Mac下常见扩展名(不包含通用的扩展,如txt/doc等)

    • app——可运行的应用程序(Windows中是.exe)
    • dmg——应用程序安装包(Windows中是exe/msi等)
      • Mac安装软件一般有三种方式:App Store方式、PKG文件或DMG文件方式、终端环境的包管理工具(如homebrew)。
    • ipa——iOS应用程序安装包(只有越狱的手机才可以安装apple商店之外的.ipa软件)
    • xcodeproj——Xcode的项目文件(双击可以直接打开整个项目,前提是已经装有Xcode软件)
    • plist——用于存储用户设置(类似Windows中的.ini)
    • bundle——可认为是压缩后的文件夹(一种压缩文件)
  2. 常用软件

三、brew使用

  1. brewMac下的一个包管理工具,类似于centos下的yum,可以很方便地进行安装/卸载/更新各种软件包,例如:nodejs,elasticsearch,kibana,mysql,mongodb`等等,可以用来快速搭建各种本地环境,程序员必备工具。

  2. 安装

    • brew是ruby开发的,需要确认ruby是否已安装,mac缺省状况下是已经安装的,可通过以下命令确认下:

      • which ruby
      • ruby -v
    • 安装ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)",默认安装在/usr/local/Homebrew目录,同时会创建一堆文件夹出来,具体如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

      ==> This script will install:
      /usr/local/bin/brew
      /usr/local/share/doc/homebrew
      /usr/local/share/man/man1/brew.1
      /usr/local/share/zsh/site-functions/_brew
      /usr/local/etc/bash_completion.d/brew
      /usr/local/Homebrew

      ==> The following new directories will be created:
      /usr/local/bin
      /usr/local/etc
      /usr/local/include
      /usr/local/lib
      /usr/local/sbin
      /usr/local/share
      /usr/local/var
      /usr/local/opt
      /usr/local/share/zsh
      /usr/local/share/zsh/site-functions
      /usr/local/var/homebrew
      /usr/local/var/homebrew/linked
      /usr/local/Cellar
      /usr/local/Caskroom
      /usr/local/Homebrew
      /usr/local/Frameworks

      Press RETURN to continue or any other key to abort
    • 卸载(不到万不得已不要卸载,卸载后之前所有的依赖都会失效,我的是因为有个问题实在解决不了了才卸载了重装就好了)

      • /bin/bash -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
  3. 常用命令:命令有很多,通过brew --hep就能查看到,此处只列举一下经常用的一些命令:

说明 命令
安装包 brew install package_name
卸载包 brew uninstall package_name
搜索包 brew search package_name
安装列表 brew list
更新包 brew update
更新某具体包 brew upgrade package_name
移除所有旧包 brew cleanup
移除某具体包 brew cleanup package_name
查看包信息 brew info package_name
查看可通过brew启动的服务 brew services list
通过brew启停服务 brew services start/stop name
  1. 例子

    • 查找包brew search redis
    • 安装包brew install redis,默认安装在/usr/local/Cellar
    • 通过brew安装的应用配置目录在/usr/local/etc/,如mysql的my.cnf,redis的redis.conf
    • 通过brew安装的应用可执行文件/usr/local/opt/对应应用,通过ll可看到实际软链到了/usr/local/Cellar
    • 通过brew安装的应用启停,以redis为例
      • brew services start redis,实际可用
      • brew services stop redis,实验后不起作用
  2. 官网

  3. cask

    • brew是从下载源码解压然后./configure && make install,同时会包含相关依存库,并自动配置好各种环境变量,而且易于卸载。
    • brew cask是已经编译好了的应用包(.dmg/.pkg),仅仅是下载解压,放在统一的目录中(/opt/homebrew-cask/Caskroom),省掉了自己去下载、解压、拖拽(安装)等步骤,同样卸载相当容易与干净。
    • 定期执行brew cleanup会释放好多磁盘空间
  4. readline

四、常见问题

MacBook Pro是苹果公司于2006年1月11日由史蒂夫·乔布斯在MacWorld 2006大会上发布的笔记本,用来取代PowerBook G4产品线。MacBook Pro与新iMac(酷睿)同为第一款转换为英特尔核心的产品。苹果在2006年10月24日发布了使用Intel Core 2 Duo处理器的MacBook Pro笔记本电脑。2009年6月8日发布了外形全新设计的“Unibody”MacBook Pro笔记本电脑。2012年WWDC上,苹果全球营销高级副总裁(SVP, Worldwide Marketing)菲尔·席勒发布了配备Retina显示器并重新设计的第三代MacBook Pro,它的分辨率高达2880x1800,220ppi。厚度仅18mm。并在此后取消17英寸产品线。2013年末,Apple更新了MacBook Pro系列,仅余下一款MacBook Pro 13”没有配备Retina显示器,但它是目前为止最后一款可以自行更换内存条(RAM)和硬盘的笔记本电脑型号。2016年10月28日,加入Touch Bar的新款MacBook Pro发布,售价13888元起。2018年7月12日,新版MacBook Pro发布,2018款MacBook Pro全系配备英特尔第八代酷睿处理器,配合True Tone技术的屏幕和Apple T2芯片,用户体验有了显著提升。2019年5月22日,Apple 为 MacBook Pro 带来更新,配备更快的第八代和第九代 Intel Core 处理器,这也是 MacBook Pro 首次搭载八核处理器。

  1. Mac无法打开“XXXX”,因为Apple无法检查其是否包含恶意软件”,输入命令sudo spctl --master-disable

  2. 刷新dns缓存sudo killall -HUP mDNSResponder

  3. SIP,全称System Integrity Protection,有时被称作rootless,中文名为系统完整性保护,它是苹果公司的macOS系统中一个安全功能,最早出现在OS X El Capitan。它由很多内核强制实施的机制构成。它的主要功能是保护系统文件及目录,以免这些文件及目录被没有特定权限的进程修改,包括root用户或者拥有root权限的用户。系统完整性保护会默认开启,但可以被关闭。

    • SIP全名System Integrity Protection(系统完整性保护),它是为了保护系统进程,文件,文档不被其它进程修改,不管是否为root user,SIP技术主要分为文件系统保护,运行时保护,内核扩展签名,文件系统保护主要是通过沙盒机制限制root权限,运行时保护,主要就是保护关键进程无法被进程代码注入,挂调试器以及内核调试等,内核扩展签名,所有的第三方kext必须被安装到/Library/Extensions,并强制使用签名。
  4. 安装完软件后提示安装包损坏,打不开怎么处理?打不开“XXX”,因为它来自身份不明的开发者

    • 打开终端,输入sudo spctl –master-disable
    • 打开系统偏好设置-》安全与隐私-》通用,勾选任何来源
    • 再次安装刚刚的软件就可以了
  5. 系统升级后,发现vs code里的git项目没法push和pull操作了,然后看到控制台里提示信息:

1
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

据说苹果每个版本更新后都有这样的问题,原因是每次安装更醒后,Xcode 都被卸载了。通过终端重新安装的Xcode命令行工具使用(其实这里安装的是Command Line Tools,Command Line Tools是在Xcode中的一款工具),执行以下命令:

1
2
3
4
5
6
xcode-select --install


softwareupdate --all --install --force
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
  1. 设置zsh为默认shell
1
2
cat /etc/shells
chsh -s /bin/zsh
  1. 输入特殊符号

    • 美元($) shift+4
    • 美分(¢) option+4
    • 英镑(£) option+3
    • 欧元(€) shift+option+2
    • 人民币(¥) option+y
    • 连接号(–) option+-
    • 破折号(—) shift+option+-
    • 省略号(…) option+;
    • 约等于(≈) option+x
    • 度(°) shift+option+8
    • 除号(÷) option+/
    • 无穷大(∞) option+5
    • 小于等于(≤) option+,
    • 大于等于(≥) option+.
    • 不等于(≠) option+=
    • 圆周率(π) option+P
    • 正负(±) shift+option+=
    • 平方根(√) option+v
    • 总和(∑) option+w
    • 商标(™) option+2
    • 注册(®) option+r
    • 版权(©) option+g
  2. Agreeing to the Xcode/iOS license requires admin privileges

    • 打开终端,输入sudo xcodebuild -license
    • 终端提示敲回车键(enter)打开许可协议,照做
    • 终端提示,一直按下space键阅读许可协议,会自动阅读到最后一行停下
    • 最终,终端会出现三个选项,agree 、print、cancel,输入agree,然后enter
  3. cpu持续很高

    • Mac系统中 mdworker、mds、mds_stores进程占领CPU
    • 这几个进程都是为了Spotlight索引而运行
    • 关闭sudo mdutil -a -i off
    • 打开sudo mdutil -a -i on
  4. SIP和csrutil

    • SIP全名System Integrity Protection(系统完整性保护),它是为了保护系统进程,文件,文档不被其它进程修改,不管是否为root user,SIP技术主要分为文件系统保护,运行时保护,内核扩展签名,文件系统保护主要是通过沙盒机制限制root权限,运行时保护,主要就是保护关键进程无法被进程代码注入,挂调试器以及内核调试等,内核扩展签名,所有的第三方kext必须被安装到/Library/Extensions,并强制使用签名。
    • SIP(System Integrity Protection,有时被称作rootless,中文名为系统完整性保护) 是苹果公司的macOS系统中一个安全功能,最早出现在OS X El Capitan。它由很多内核强制实施的机制构成。它的主要功能是保护系统文件及目录,以免这些文件及目录被没有特定权限的进程修改,包括root用户或者拥有root权限的用户。
    • 苹果公司指出root用户会是系统安全性的一个严重危害因素,特别当系统上只有一个用户账户,且这个用户账户是administrator。系统完整性保护会默认开启,但可以被关闭。
1
2
3
4
①重启OSX系统,然后按住Command+R
②出现界面之后,选择Utilities menu中Terminal
③在Terminal中输入csrutil disable关闭SIP(csrutil enable打开SIP)
④重启reboot OSX
  1. xcode-select
          在从App Store上下载Xcode后,默认不会安装Command Line ToolsCommand Line Tools是在Xcode中的一款工具,可以在命令行中运行C程序。安装Xcode command line tools,直接在终端中运行xcode-select --install即可。如果你不是一名iOSOS X开发者,可以跳过安装XCode的过程,直接安装Xcode command line tools。安装完成后你将可以直接在terminal中使用主要的命令,比如make,GCC,clang,perl,svn,git,size,strip,strings,libtool,cpp等。想了解Xcode command line tools包含多少可用的命令,可以到/Library/Developer/CommandLineTools/查看。

  2. Read-only file system

    当Mac升级到最新的版本Catalina后,在根目录或者其他系统目录下进行文件修改就会提示:Read-only file system.

    Mac升级之前只要获得权限后就可以在几乎任何目录下新建和删除文件。但是当Mac升级到最新的版本Catalina后,当在根目录或者其他系统目录下进行文件修改就会提示:Read-only file system,这是因为苹果引入了SIP技术所致。SIP全称为System Integrity Protection,即系统完整性保护,是OS X El Capitan时开始采用的一项安全技术。它将一些文件目录和系统应用保护了起来,这会影响我们一些使用或设置,比如:更改系统应用图标、终端操作系统目录文件提示Operation not permittedFinder无法编辑系统目录里的文件,以及此篇主题Read-only file system

    • 关闭SIP
    • 重启Mac
    • 进入macOS恢复功能(重启时按command + r)
    • 顶部导航栏实用工具->终端
    • 在终端中数据命令csrutil disable
      • 查看csrutil status
    • 挂载根目录sudo mount -uw /
    • 执行对应的操作,如sudo mkdir -p /data/home/
    • 启用SIP(根据个人情况而定,如果经常要要操作则没必要)
    • 参考
    • macOS Catalina
    • macOS 恢复功能
    • macOS 开启或关闭SIP
    • Read-only file system
  3. brew安装程序时报错

    • Mac报错 Error: The following directories are not writable by your user: /usr/local/share/man/man8
    • 解决方案
    • 执行命令 sudo chown -Rwhoami:admin /usr/local/bin
    • 输入密码
    • 执行命令 sudo chown -Rwhoami:admin /usr/local/share
  4. mac之用户管理命令dscl

  5. mac下运行C语言程序

    • 若要在Mac的终端中编译并运行C源代码,你首先需要安装Command Line Tools,里面包含有GCC编译器。
    • 安装GCC编译器方法:
    • 打开终端,输入gcc
    • 如果没有安装`Command Line Tools1,会弹出一个窗口提示安装,点击安装即可。
    • 如果出现提示“no input files”,说明你已经安装了gcc编译器,可以直接开始编译程序。
    • 使用编译器将源文件中的代码转换为二进制代码,这个过程叫做编译。
    • 将终端的工作路径切换到源文件所在的路径。
    • 执行命令:gcc -c 源文件的名称,如:gcc -c test.c
    • 如果没有意外的话,就会在当前工作路径下生成一个test.o文件,这个文件叫做目标文件,目标文件存储的是test.c文件中代码对应的二进制指令。
    • 一个程序如果想要交给CPU执行,只是有二进制指令是不行的,还必须为这个目标文件添加一些启动代码,添加启动代码的过程叫做链接。
    • 执行命令:gcc 目标文件名称,如:gcc test.o
    • 如果一切正常的情况下,就会生成一个a.out文件,这个文件就是最终可以执行的程序了。
    • 执行这个a.out程序,就可以看到程序的执行结果了,如:./a.out
  6. mac下laravel项目初始化

    本地开发环境Macbook Pro,日常工作中主要用php5.6版本,最新的laravel框架要求PHP >= 7.1.3,索性装了个php7.3,工作中业务开发和自己学习时来回切换php版本。也可以按照laravel官网说的装一个homestead虚拟机,或者通过vagrant+virtualbox装不同版本的虚拟机,BZ都倒腾过,感觉虚拟就跑的时间长了内存都被吃完了,就在本机倒腾。

1
2
ln -f /usr/local/php/5.6/bin/php /usr/local/bin/php5.6
ln -f /usr/local/php/7.3/bin/php /usr/local/bin/php7.3
  • 安装composer

    • 方式一:php下载安装模式

      1
      2
      3
      4
      php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
      php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
      php composer-setup.php
      php -r "unlink('composer-setup.php');"
    • 直接下载compser.phar https://getcomposer.org/download/1.8.6/composer.phar

    • mv /path/composer.phar /usr/local/bin/composer

    • php5.6/php7.3 /usr/local/bin/composer require package

  • 初始化laravel

  • php7.3 /usr/local/bin/compsoer global require “laravel/installer”

  • laravel new laravel-blog

    • 报错: laravel: command not found
    • 解决:export PATH=”/your home path/composer/vendor/bin:$PATH”
    • 报错:env: php: No such file or directory
    • 解决:暂未解决,原因是composer/laravel脚本首行指定的运行环境是#!/usr/bin/env php
  • 换一种方式 php7.3 /usr/local/bin/composer create-project --prefer-dist laravel/laravel laravel-blog


各种安装

一、RabbitMQ安装

  1. 使用brew安装
  • 更新库 brew update
  • 安装服务 brew install rabbitmq,此过程会自动安装依赖
  • 启动服务 cd /usr/local/Cellar/rabbitmq/3.7.16 && ./sbin/rabbitmq-server
  • 有如下输出则表示启动成功
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ##  ##
    ## ## RabbitMQ 3.7.16. Copyright (C) 2007-2019 Pivotal Software, Inc.
    ########## Licensed under the MPL. See https://www.rabbitmq.com/
    ###### ##
    ########## Logs: /usr/local/var/log/rabbitmq/rabbit@localhost.log
    /usr/local/var/log/rabbitmq/rabbit@localhost_upgrade.log

    Starting broker...
    completed with 6 plugins.
  • 访问控制页面,在浏览器输入:localhost:15672,默认用户名/密码为guest/guest
  1. 源码安装

二、Docker

  1. 下载dmg安装
  1. 使用brew安装
    • 安装时使用brew cask install docker一条命令即可,安装成功后会提示🍺 docker was successfully installed!
    • 正常启动docker,则会在/usr/local/bin目录下生成可执行文件
    • 卸载brew cask uninstall docker

三、java环境搭建

  1. 安装Java
  • 下载jdk

  • 双击安装dmg文件

  • 测试是否安装成功 java --version

  • 配置PATH和CALSSPATH路径 sudo vim /etc/profile,末尾处添加以下内容

    • CLASS_PATH保证class文件能够在任意目录下运行

    • PATH保证javac可以在任意目录下运行

      1
      2
      3
      JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/"
      CLASS_PATH="$JAVA_HOME/lib"
      PATH=".:$PATH:$JAVA_HOME/bin"
  • 刷新配置PATH和CLASSPATH source /etc/profile

  • 查看$JAVA_HOME路径 echo $JAVA_HOME

  • 测试脚本 touch test.java

1
2
3
4
5
6
class Hello {

public static void main(String[] args) {
System.out.println("Helllo");
}
}
  • javac test.java看是否生成class文件
  • java Hello看是否有输出Hello
  1. 安装Tomcat
    • 下载源码包,选择xxx.tar.gz文件
    • 解压 sudo tar -zxvf apache-tomcat-9.0.22.tar.gz
    • 确定安装目录 sudo mv apache-tomcat-9.0.22 /usr/local/
    • 进入安装目录 cd /usr/local/apache-tomcat-9.0.22
    • 启动c sudo sh /usr/local/apache-tomcat-9.0.22/bin/startup.sh
      • 关闭Tomcat sudo sh /usr/local/apache-tomcat-9.0.22/bin/shutdown.sh
    • 在地址栏输入 localhost:8080,出现Tomcat页面就OK

四、mac下安装多版本composer

五、MAC下通过vagrant+virtualbox搭建LNMP环境

  1. 安装virtualbox

  2. 安装vagrant

  3. 下载linux.box(centos/ubuntu等)

    • vagrant box add centos/7(此名称通过vagrant box列表获得),在终端里会显示下载进度,将地址复制粘贴到迅雷等下载工具
    • box下载 列表地址
  4. 创建linux.json(名字随便起)文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
      
    {

    "name": "centos7",#名字随便

    "versions": [
    {
    "version": "18.10.09",#版本随便
    "providers": [
    {
    "name": "virtualbox",
    "url": "/Users/your_name/box-folder/centos7.box"
    }
    ]
    }
    ]
    }
  5. vagrant box add linux.json(或者box名字,这种形式很慢,推荐提前下载好box文件)

  6. mkdir folder_name ,运行 vagrant box list 查看是否添加成功

  7. 步骤4、步骤5还可以这样,cd folder_name , vagrant init 会产生 Vagrantfile,编辑此文件,找到 config.vm.box = box本地地址

  8. vagrant up

  9. centos7 VM VirtualBox设置共享目录时报错,解决办法如下:

1
2
3
4
 + vagrant plugin install vagrant-vbguest
+ yum clean all
+ yum update
+ yum install kernel install kernel-devel kernel-headers gcc make
  • 回到mac,vagrant reload –provision
  1. vagrant ssh 登入后正常搭建LNMP环境就行了,网上的教程一大堆

六、Mac下php-intl扩展安装

  1. 安装icu依赖

  2. 安装intl扩展

    • 官网下载
    • 解压 tar -zxvf intl-3.0.0.tgz
    • cd intl-3.0.0
    • /path/phpize
    • ./configure –with-php-config=/path/php-config –with-icu-dir=/path/icu
    • sudo make && sudo make install

七、Mac下php-gd扩展安装:

使用composer安装的时候提示phpoffice/phpspreadsheet 1.6.0 requires ext-gd *,安装gd扩展的时候又提示configure: error: png.h not found.

使用命令安装报错,brew install libpng,/usr/local/xxx/man8没有权限,使用chmod修改了也不起作用,故编译安装

  1. 安装依赖libpng

    • 下载源码包
    • 移动到源码目录 mv libpng-1.6.16.tar.gz /usr/local/src/
    • 解压 cd /usr/local/src && tar -zxvf libpng-1.6.16.tar.gz
    • 切换至解压后的目录 cd libpng-1.6.16
    • ./configure --prefix=/usr/local/libpng
    • sudo make && sudo make install
  2. 安装gd

    • 进入php5.6源码包 cd /usr/local/src/php-5.6.27/ext/gd
    • sudo /usr/local/php/5.6/bin/phpize
    • sudo ./configure --with-php-config=/usr/local/php/5.6/bin/php-config --with-png-dir=/usr/local/libpng
    • sudo make && sudo make install
    • 修改php.ini文件,加入extension=gd.so

八、Mac下安装php报错

  1. 报错:The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config.

    • 解决:brew install pkg-config
      • pkg-config能够列出系统已经安装的库的相关信息,如库的路径和头文件路径,特别是在预处理和编译的时候,能够告诉gcc等编译器程序依赖的库和头文件的位置。
  2. 报错:Please specify the install prefix of iconv with --with-iconv=<DIR>

    • 解决:brew install libiconv
      • libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。
  3. 报错:fatal error:'libxml/parser.h' file not found

    • 解决1:brew install libxml2

      • 报错,brew安装失败
      1
      2
      3
      4
      5
      6
      7
      8
      9
      cp: /private/tmp/d20210324-55179-1pe5j38/libxml2/./2.9.10_2: unable to copy ACL to /usr/local/Cellar/libxml2/2.9.10_2: No such file or directory
      cp: utimes: /usr/local/Cellar/libxml2: No such file or directory
      cp: chown: /usr/local/Cellar/libxml2: No such file or directory
      cp: chmod: /usr/local/Cellar/libxml2: No such file or directory
      cp: chflags: /usr/local/Cellar/libxml2: No such file or directory
      cp: /private/tmp/d20210324-55179-1pe5j38/libxml2/.: unable to copy ACL to /usr/local/Cellar/libxml2: No such file or directory
      Error: Failure while executing; `cp -pR /private/tmp/d20210324-55179-1pe5j38/libxml2/. /usr/local/Cellar/libxml2` exited with 1. Here's the output:
      cp: /usr/local/Cellar/libxml2: No such file or directory
      cp: /private/tmp/d20210324-55179-1pe5j38/libxml2/.: unable to copy extended attributes to /usr/local/Cellar/libxml2: No such file or directory
    • 解决2:去官网下载源码安装

      • libxml是一个用来解析XML文档的函数库,它用C语言写成,并且能为多种语言所调用,例如C/C++/C#/Python/Ruby/PHP等。
    • 解决3:brew install libxml2安装成功

      • ln -s /usr/local/opt/libxml2/include/libxml2/libxml /usr/local/include/libxml

九、Mac下MySQL安装

  1. dmg安装

    • 进入MySQL官网
    • 选择DOWNLOADS
    • 选择Community
    • 选择MySQL Community Server
    • 选择对应的环境macOS
    • 找到mysql-8.0.16-macos10.14-x86_64.dmg,点击Download
    • 选择No thanks, just start my download.
    • 下载完成后双击安装就行了
    • 安装完成后,输入mysql -u root -p提示mysql: command not found
    • 进入当前用户的根目录 cd ~
    • vim .bash_profile(有则直接编辑,无则创建)
    • 添加 PATH=$PATH:/usr/local/mysql/bin(更换为你自己的安装目录)
    • source ~/.bash_profile
    • 打完收工
    • 如果是mysql8安装过程中会有设置密码的步骤,如果是mysql5.7则在安装过程中会给一个临时密码
    • mysql -uroot -p
    • SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
    • 打完
  2. 编译安装

  3. brew安装

    • 查看可安装的包brew search mysql
    1
    2
    3
    4
    5
    6
    7
    8
    ==> Formulae
    automysqlbackup mysql-client@5.7 mysql@5.6
    mysql mysql-connector-c++ mysql@5.7 ✔
    mysql++ mysql-sandbox mysqltuner
    mysql-client mysql-search-replace qt-mysql
    ==> Casks
    mysql-connector-python mysql-utilities navicat-for-mysql
    mysql-shell mysqlworkbench sqlpro-for-mysql
    • 安装对应的包brew install mysql@5.7
  4. 问题

    • 通过brew安装的MySQL配置文件在哪儿cd /usr/local/Cellar/mysql@5.7/5.7.32/bin/ && ./mysqld --help --verbose | less

      • 修改datadir,vim /usr/local/etc/my.cnf,在[mysqld]下加入
      1
      datadir = /usr/local/mysql/data
    • 安装后启动与关闭

      • mysql.server start
      • mysql.server stop
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      2014-03-31T10:38:55.6NZ mysqld_safe Logging to '/usr/local/mysql/data/xxxxdeMacBook-Air-5.local.err'.
      2014-03-31T10:38:55.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
      2014-03-31T10:38:55.586806Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
      2014-03-31T10:38:55.587174Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
      2014-03-31T10:38:55.587229Z 0 [Note] /usr/local/Cellar/mysql@5.7/5.7.32/bin/mysqld (mysqld 5.7.32) starting as process 53974 ...
      2014-03-31T10:38:55.592524Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
      2014-03-31T10:38:55.592566Z 0 [Note] InnoDB: Uses event mutexes
      2014-03-31T10:38:55.592577Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
      2014-03-31T10:38:55.592587Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
      2014-03-31T10:38:55.592913Z 0 [Note] InnoDB: Number of pools: 1
      2014-03-31T10:38:55.593055Z 0 [Note] InnoDB: Using CPU crc32 instructions
      2014-03-31T10:38:55.594398Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
      2014-03-31T10:38:55.605039Z 0 [Note] InnoDB: Completed initialization of buffer pool
      2014-03-31T10:38:55.620905Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
      2014-03-31T10:38:55.636870Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
      2014-03-31T10:38:55.637241Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
      2014-03-31T10:38:55.673043Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
      2014-03-31T10:38:55.674434Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
      2014-03-31T10:38:55.674492Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
      2014-03-31T10:38:55.675189Z 0 [Note] InnoDB: 5.7.32 started; log sequence number 1209999
      2014-03-31T10:38:55.675571Z 0 [Note] Plugin 'FEDERATED' is disabled.
      mysqld: Table 'mysql.plugin' doesn't exist
      2014-03-31T10:38:55.676191Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
      2014-03-31T10:38:55.676276Z 0 [Note] InnoDB: Loading buffer pool(s) from /usr/local/mysql/data/ib_buffer_pool
      2014-03-31T10:38:55.676590Z 0 [ERROR] unknown variable 'mysqlx-bind-address=127.0.0.1'
      2014-03-31T10:38:55.676634Z 0 [ERROR] Aborting

      2014-03-31T10:38:55.676696Z 0 [Note] Binlog end
      2014-03-31T10:38:55.676749Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210331 18:38:55
      2014-03-31T10:38:55.676793Z 0 [Note] Shutting down plugin 'ngram'
      2014-03-31T10:38:55.676860Z 0 [Note] Shutting down plugin 'partition'
      2014-03-31T10:38:55.676897Z 0 [Note] Shutting down plugin 'BLACKHOLE'
      2014-03-31T10:38:55.676921Z 0 [Note] Shutting down plugin 'ARCHIVE'
      2014-03-31T10:38:55.676945Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
      2014-03-31T10:38:55.677037Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
      2014-03-31T10:38:55.677075Z 0 [Note] Shutting down plugin 'MyISAM'
      2014-03-31T10:38:55.677206Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
      2014-03-31T10:38:55.677247Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
      2014-03-31T10:38:55.677269Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
      2014-03-31T10:38:55.677286Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
      2014-03-31T10:38:55.677302Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
      2014-03-31T10:38:55.677316Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
      2014-03-31T10:38:55.677330Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
      2014-03-31T10:38:55.677343Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
      2014-03-31T10:38:55.677357Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
      2014-03-31T10:38:55.677371Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
      2014-03-31T10:38:55.677386Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
      2014-03-31T10:38:55.677402Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
      2014-03-31T10:38:55.677429Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
      2014-03-31T10:38:55.677442Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
      2014-03-31T10:38:55.677454Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
      2014-03-31T10:38:55.677467Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
      2014-03-31T10:38:55.677479Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
      2014-03-31T10:38:55.677492Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
      2014-03-31T10:38:55.677505Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
      2014-03-31T10:38:55.677517Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
      2014-03-31T10:38:55.677529Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
      2014-03-31T10:38:55.677541Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
      2014-03-31T10:38:55.677554Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
      2014-03-31T10:38:55.677566Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
      2014-03-31T10:38:55.677578Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
      2014-03-31T10:38:55.677590Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
      2014-03-31T10:38:55.677656Z 0 [Note] Shutting down plugin 'INNODB_CMP'
      2014-03-31T10:38:55.677675Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
      2014-03-31T10:38:55.677683Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
      2014-03-31T10:38:55.677691Z 0 [Note] Shutting down plugin 'INNODB_TRX'
      2014-03-31T10:38:55.677702Z 0 [Note] Shutting down plugin 'InnoDB'
      2014-03-31T10:38:55.677808Z 0 [Note] InnoDB: FTS optimize thread exiting.
      2014-03-31T10:38:55.677941Z 0 [Note] InnoDB: Starting shutdown...
      2014-03-31T10:38:55.781304Z 0 [Note] InnoDB: Dumping buffer pool(s) to /usr/local/mysql/data/ib_buffer_pool
      2014-03-31T10:38:55.789756Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 210331 18:38:55
      2014-03-31T10:38:57.141615Z 0 [Note] InnoDB: Shutdown completed; log sequence number 1210018
      2014-03-31T10:38:57.145029Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
      2014-03-31T10:38:57.145167Z 0 [Note] Shutting down plugin 'MEMORY'
      2014-03-31T10:38:57.145206Z 0 [Note] Shutting down plugin 'CSV'
      2014-03-31T10:38:57.145255Z 0 [Note] Shutting down plugin 'sha256_password'
      2014-03-31T10:38:57.145295Z 0 [Note] Shutting down plugin 'mysql_native_password'
      2014-03-31T10:38:57.145700Z 0 [Note] Shutting down plugin 'binlog'
      2014-03-31T10:38:57.146078Z 0 [Note] /usr/local/Cellar/mysql@5.7/5.7.32/bin/mysqld: Shutdown complete
      2014-03-31T10:38:57.6NZ mysqld_safe mysqld from pid file /usr/local/mysql/data/xxxxdeMacBook-Air-5.local.pid ended
      • 折腾了好久还是不行,因为公司的mac之前装过MySQL,如果数据文件和索引还存在的话可能会影响启动,不破不立,直接把之前的数据全删掉。

        • brew uninstall mysql@5.7
        • sudo rm /usr/local/mysql
        • sudo rm /usr/local/var/mysql
        • sudo rm /usr/local/etc/my.cnf
      • 重新安装brew install mysql@5.7

      • 启动mysql.server start,打完收工

      • 设置环境变量,自己GG一下

    • 设置初始密码mysql_secure_installation

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    mysql_secure_installation

    Securing the MySQL server deployment.

    Connecting to MySQL using a blank password.

    VALIDATE PASSWORD PLUGIN 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 plugin?

    Press y|Y for Yes, any other key for No: y

    There are three levels of password validation policy:

    LOW Length >= 8
    MEDIUM Length >= 8, numeric, mixed case, and special characters
    STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

    Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
    Please set the password for root here.

    New password:

    Re-enter new password:


    Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
    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
    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) :

    ... 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!
    • 密码不符合规范:Estimated strength of the password: 25,需要重新设置,重复上面的过程即可。
  5. 参考

十、Mac下安装使用rust

  1. 安装Rust的主要方式是通过Rustup这一工具,它既是一个Rust安装器又是一个版本管理工具,Cargo则既是构建工具又是包管理器的最新稳定版。
  2. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    • 选择默认安装1即可
1
2
3
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
  • 在安装Rustup时也会安装Rust构建工具和包管理器的最新稳定版,即Cargo,它可以做很多事情:
    • cargo build 可以构建项目
    • cargo run 可以运行项目
    • cargo test 可以测试项目
    • cargo doc 可以为项目构建文档
    • cargo publish 可以将库发布到 crates.io。
  1. 安装完成后执行source $HOME/.cargo/env
  2. demo
    • cargo new hello-rust
    • cargo run
  1. 参考

十一、各种收集

  1. Mos

十二、查找大文件

  1. 安装homebrew
  2. brew install ncdu
  3. cd && ncdu

十二、更新系统出问题

  1. Warning: You are using macOS 13.
1
2
3
4
5
6
7
Warning: You are using macOS 13.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
pre-release version.

这是由于系统更新,某些文件的权限被更改导致的,于是开始更新brew,使其能正常使用

1
2
3
4
5
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
brew update