mac安装mysql

作者: 卓三阳 | 来源:发表于2017-12-03 00:46 被阅读49次

1.使用安装包安装mysql

  • mysql官网下载dmg文件,下载好后双开打开

  • 双击pkg文件安装 p1.png
  • 一路安装,最后会有一个弹框,记住root用户密码


    p2.png
  • 安装成功,但我们还需要进行额外的配置:
    (1) 进入系统偏好设置,点击mysql,并启动mysql服务


    p3.png

(2)此时我们在命令行输入mysql -uroot -p命令会提示没有commod not found
(3)进入/usr/local/mysql/bin,查看此目录下是否有mysql
(4)我们在命令行运行下面两条命令:

alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin

这个方法只是暂时有效,关闭终端后就无效了,如果想永久有效,需要将/usr/local/mysql/bin/ 加入系统path
在终端输入

vim ~/.bash_profile

用 i 命令进入插入模式,在文件末尾加入

PATH=$PATH:/usr/local/mysql/bin

按esc退出到一般模式,按:wq保存退出

(5)最后在命令行输入

source ~/.bash_profile
读取并执行文件中的命令

(6)我们再次在命令行输入mysql -uroot -p,输入刚刚记录的密码,登录成功
通过下面的命令修改密码

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

到这一步,我们就算完成了mysql的安装

笔者到这就很奇怪了,我一步一步按照上面的标准步骤安装,竟然还是不能执行mysql命令。崩溃。。。。
用了一个多小时找问题,竟然发现是内核的问题,忍不住眼泪掉下来。由于我使用的是zsh,这个我在终端美化升级中提到过。
如果你使用的是zsh内核,就应该在.zshrc文件中添加mysql路径

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

命令行操作MySQL服务,当然你也可以像前面一样从系统偏好开启关闭

  • 启动MySQL服务
sudo /usr/local/mysql/support-files/mysql.server start
  • 停止MySQL服务
sudo /usr/local/mysql/support-files/mysql.server stop
  • 重启MySQL服务
sudo /usr/local/mysql/support-files/mysql.server restart

如果记不住这么长的路径,你可以使用alias命令简写。

2.使用homebrew安装mysql

安装命令

brew install mysql

后面还有一堆配置。。。

到这里,mysql的安装就结束了,我这里还是推荐第一种安装包的形式安装。谢谢~

最后

但是小编担心使用zsh内核的小伙伴会意外删除或破坏.zshrc文件,我这里给出一个原始文件备份:

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
 
# Path to your oh-my-zsh installation.
export ZSH=/Users/zhuozenghua/.oh-my-zsh
 
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"
 
# Set list of themes to load
# Setting this variable when ZSH_THEME=random
# cause zsh load theme from this variable instead of
# looking in ~/.oh-my-zsh/themes/
# An empty array have no effect
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
 
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
 
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
 
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
 
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
 
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
 
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
 
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
 
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
 
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
 
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
 
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
 
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git
)
 
source $ZSH/oh-my-zsh.sh
 
# User configuration
 
# export MANPATH="/usr/local/man:$MANPATH"
 
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
 
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi
 
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
 
# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"
 
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

相关文章

网友评论

    本文标题:mac安装mysql

    本文链接:https://www.haomeiwen.com/subject/odbobxtx.html