美文网首页
一次重装MySQL的经历

一次重装MySQL的经历

作者: 醋溜八酱 | 来源:发表于2019-01-30 15:14 被阅读0次

    我是brew安装的MySQL,所以删除起来很麻烦,各种残留项都没有办法解决,最后各种查资料花了三个小时总算搞定了!分享一下我的经历,希望能够帮助到其他小伙伴们。


    首先,brew自带的卸载MySQL命令:

    brew remove mysql
    

    删除brew的安装包目录以及其他杂项:

    # 我的MySQL是5.7版本,大家各自对号入座
    sudo rm -rf /usr/local/Cellar/mysql@5.7  
    # 下面的无论哪个版本都可以执行,如果没有找到目录就直接略过
    sudo rm -rf /usr/local/var/mysql
    sudo rm -rf /tmp/mysql.*
    sudo rm -rf /tmp/mysqlx.sock
    sudo rm -rf /tmp/mysqlx.sock.lock
    sudo rm -rf /usr/local/Library/Cache/Homebrew
    sudo rm /usr/local/mysql
    sudo rm -rf /usr/local/mysql*
    sudo rm -rf /Library/StartupItems/MySQLCOM
    sudo rm -rf /Library/PreferencePanes/My*
    rm -rf ~/Library/PreferencePanes/My*
    sudo rm -rf /Library/Receipts/mysql*
    sudo rm -rf /Library/Receipts/MySQL*
    sudo rm -rf /var/db/receipts/com.mysql.*
    

    清理

    brew cleanup
    brew uninstall mysql
    

    安装MySQL

    # 依然使用brew安装(自己作)
    brew install mysql@5.7
    

    下面分为两种情况,请各位看官对号入座:

    情况一:

    # 如果出现这样情况,那么就算安装成功了,可以直接跳过下一段,看配置了
    ➜  ~ brew postinstall mysql@5.7
    ==> Postinstalling mysql@5.7
    ==> /usr/local/Cellar/mysql@5.7/5.7.24/bin/mysqld --initialize-insecure --user=f
    

    情况二:

    [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2019-01-30T06:25:31.095656Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
    2019-01-30T06:25:31.242178Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2019-01-30T06:25:31.266992Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2019-01-30T06:25:31.319878Z 0 [ERROR] unknown variable 'validate_password=off'
    2019-01-30T06:25:31.319925Z 0 [ERROR] Aborting
    
    
    
    
    # 如果出现这种情况,你需要进行以下配置
    rm -rf /usr/local/var/mysql
    # 这里插句话,如果使用官方的dmg镜像安装的话,用这条命令
    rm -rf /usr/local/mysql
    然后执行:
    brew postinstall mysql@5.7
    

    大功告成!!!

    配置:

    # 这部分转载的 https://www.jianshu.com/p/c103776c014f
    mysql_secure_installation
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
    SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
    In order to log into MySQL to secure it, we'll need the current
    password for the root user. If you've just installed MySQL, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    Enter current password for root (enter for none):<–初次运行直接回车
    OK, successfully used password, moving on…
    Setting the root password ensures that nobody can log into the MySQL
    root user without the proper authorisation.
    Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
    New password: <– 设置root用户的密码
    Re-enter new password: <– 再输入一次你设置的密码
    Password updated successfully!
    Reloading privilege tables..
    … Success!
    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? [Y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车
    … 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? [Y/n] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
    … Success!
    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? [Y/n] <– 是否删除test数据库,直接回车
    - Dropping test database…
    … Success!
    - Removing privileges on test database…
    … Success!
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    Reload privilege tables now? [Y/n] <– 是否重新加载权限表,直接回车
    … Success!
    Cleaning up…
    All done! If you've completed all of the above steps, your MySQL
    installation should now be secure.
    Thanks for using MySQL!
    

    相关文章

      网友评论

          本文标题:一次重装MySQL的经历

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