美文网首页MySQL&DBs
Mac安装配置Mysql 5.7

Mac安装配置Mysql 5.7

作者: 素纸鸢 | 来源:发表于2018-09-19 20:19 被阅读23次

    最近换了新的电脑,于是各种环境各种配,遇到了不少奇葩问题,这篇博客对一些比较棘手的问题进行整理(每个问题几乎都耽误了我3个小时)。。。

    1.MAC 安装mysql 5.7.13

    首先是mysql 问题,我安装的mysql 5.7.13 是当前最新的版本。在mysql 官网https://www.mysql.com/downloads/下载最新的mysql 安装包(如:mysql-5.7.13-osx10.11-x86_64.dmg)

    然后双击打开,按照提示进行下一步,安装完毕后mysql 会给你一个临时的密码 如图(有时侯也会没有这个临时密码,我第一次安装时就没有临时密码)。

    [图片上传失败...(image-702a13-1537359548634)]

    安装完成后,在终端访问mysql。首先要配置PATH路径,编辑文件profile;

    $ vi ~/.bash_profile

    添加如下语句:
    export PATH=$PATH:/usr/local/mysql/bin

    输入 alias 命令
    alias mysql=/usr/local/mysql/bin/mysql

    回车,在输入
    alias mysqladmin=/usr/local/mysql/bin/mysqladmin

    在/usr/local/mysql/bin 目录下登录mysql

    $ mysql -u root -p
    如果有临时密码输入临时密码;

    登录后无论执行什么语句都会提示你修改临时密码方可操作,
    (报错 :ERROR 1820 (HY000): You must reset your password using ALTER USER statement)

    此时执行:
    alter user 'root'@'localhost' identified by 'root';

    然后再执行修改密码操作 (如果没有效果可与上一条命令交替之行。)

    mysql> update mysql.user set authentication_string=PASSWORD('你的密码’) where user='root';

    密码修改后即可正常操作mysql 。

    如果安装完成后没有给临时密码也不要着急,这时候只需绕过验证即可。

    输入命令:
    mysqld_safe --skip-grant-tables &

    绕过验证,保持当前终端,再次打开一个终端,
    执行 mysql -u root -p 命令,即可直接进入mysql ,

    然后执行
    alter user 'root'@'localhost' identified by 'root';

    然后再执行修改密码操作 (如果没有效果可与上一条命令交替之行。)

    mysql> update mysql.user set authentication_string=PASSWORD('你的密码’) where user='root';

    即可修改密码成功,可正常操作mysql

    2.MAC 安装Homebraew

    brew 是mac的一款很方便的套件管理器,当brew安装成功后,就可以随意安装自己想要的软件了,例如wget,命令如下:

    安装brew 要先安装git 因为brew 需要使用git。
    sudo brew install wget

    安装brew 打开终端,执行官方的安装命令:
    /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

    安装时如果一切正常,即可。

    执行 brew –help 命令查看提示是否安装成功。

    如果报错 多半是没有权限,而且 brew 还不支持 root 用户安装,所以此时,就要查看是那些文件夹没有权限,并赋予权限。(例如 .github 文件夹 。下边错误是share/doc/homebrew文件夹没有权限)
    fatal: cannot unlink ‘Library/Aliases/0install’: Permission denied
    error: unable to unlink old ‘share/doc/homebrew/Acceptable-Formulae.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/Bottles.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/Brew-Test-Bot-For-Core-Contributors.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/Brew-Test-Bot.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/C++-Standard-Libraries.md’ (Permission denied)
    error: unable to create file share/doc/homebrew/Checksum_Deprecation.md (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/Common-Issues-for-Core-Contributors.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/Common-Issues.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/Custom-GCC-and-cross-compilers.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/External-Commands.md’ (Permission denied)
    error: unable to unlink old ‘share/doc/homebrew/FAQ.md’ (Permission denied)

    此时只用修改相关文件夹的所有者权限即可。

    查看文件或文件夹的所有者权限命令如下
    ls -rlt

    修改权限命令如下 :
    chown 用户名 /需要修改权限的文件或文件夹路径
    例如(chown zhangsan /usr/local/.github)
    就是将.github文件夹的所有权zhangsan这个用户。

    缺少权限的文件夹可能会有比较多,此时需要有耐心的去看报错信息,进行修改。

    如果安装失败需要卸载重新安装,卸载命令如下:
    先执行
    /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)”
    然后复制执行如下脚本(一次全部复制粘贴)
    cd brew --prefix
    rm -rf Cellar
    brew prune
    rm git ls-files
    rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
    rm -rf .git
    rm -rf ~/Library/Caches/Homebrew

    此时就已经将brew 卸载干净,可充新安装。

    遇到错误不要怕,认真看清错误信息再进行搜索,不要直接复制错误信息搜索,应该仔细看一下报错内容进行准确搜索。

    相关文章

      网友评论

        本文标题:Mac安装配置Mysql 5.7

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