Macbook通过brew安装mysql8.0

😀 通过brew安装mysql@8.0

前言

MySQL 8 是mysql的最新版本,它带来了许多改进和新特性,主要新增特性如下:

  1. 公用表表达式(CTE) : CTE 可以简化复杂的 JOIN 查询和子查询,并支持递归查询,提高 SQL 的可读性和执行性能。

  2. 默认字符集变更 : 默认字符集由 latin1 变为 utf8mb4,utf8 也默认指向 utf8mb4,支持更多的 Unicode 字符。

  3. 克隆插件 : 提供了从一个实例克隆出另一个实例的功能,有助于快速创建 MySQL 实例和搭建复制环境。

  4. 资源组 : 允许调控线程优先级和绑定 CPU 核,需要相应的权限和系统支持。

  5. 角色管理 : 角色可以看作是权限的集合,简化了权限管理。

  6. 参数修改持久化 : 支持在线修改全局参数并持久化到配置文件中。

  7. InnoDB 锁等待改进 : 新增 NOWAIT 和 SKIP LOCKED 语法,允许跳过锁等待。

  8. GROUP BY 排序行为变更 : 为了兼容 SQL 标准,不再隐式排序。

  9. 自适应参数 : 自动调整参数以适应服务器的硬件配置。

  10. 窗口函数 : 从 MySQL 8.0 开始,引入了窗口函数,提供了新的查询方式。

  11. 性能提升 : 官方表示 MySQL 8.0 的性能是 MySQL 5.7 的两倍,特别是在读/写工作负载、IO 密集型工作负载和高竞争工作负载方面。

  12. JSON 扩展 : 提供了更多的 JSON 功能,包括 JSON 表函数和聚合函数。

  13. GIS 地理支持 : 增强了对地理信息系统的支持。

  14. DDL 原子性和崩溃安全 : 改进了数据定义语言的可靠性。

  15. 性能架构改进 : 提升了性能架构的可观察性。

  16. 安全增强 : 包括 OpenSSL 改进、新的默认身份验证、SQL 角色等。

  17. 错误日志改进 : 错误日志系统进行了重大改进,提供了更多的灵活性和自定义选项。

  18. 可管理性增强 : 包括撤销表空间管理、全局变量持久化等。

  19. 远程管理 : 通过 SQL RESTART 命令等实现远程管理。

博主发现自己的mysql版本还停留在5.7,从mysql8导出的数据居然无法导入mysql5.7,于是将mysql版本升级到了8.0,如下是博主的安装记录,供各位同学参考

📝 主旨内容

  1. brew安装

    css 复制代码
    brew install mysql@8.0

    安装成功会输出提示:

    vbnet 复制代码
    We've installed your MySQL database without a root password. To secure it run:
        mysql_secure_installation
    
    MySQL is configured to only allow connections from localhost by default
    
    To connect run:
        mysql -u root
    
    mysql@8.0 is keg-only, which means it was not symlinked into /opt/homebrew,
    because this is an alternate version of another formula.
    
    If you need to have mysql@8.0 first in your PATH, run:
      echo 'export PATH="/opt/homebrew/opt/mysql@8.0/bin:$PATH"' >> ~/.zshrc
    
    For compilers to find mysql@8.0 you may need to set:
      export LDFLAGS="-L/opt/homebrew/opt/mysql@8.0/lib"
      export CPPFLAGS="-I/opt/homebrew/opt/mysql@8.0/include"
    
    To start mysql@8.0 now and restart at login:
      brew services start mysql@8.0
    Or, if you don't want/need a background service you can just run:
      /opt/homebrew/opt/mysql@8.0/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql

    可按照提示信息完成mysql配置。

  2. 环境配置

    1. 查看brew安装mysql得路径

      css 复制代码
      brew --prefix mysql
    2. 编辑环境变量,注意修改路径

      bash 复制代码
      # 编辑环境变量
      sudo vi ~/.zshrc
      
      # 增加以下内容
      export PATH="/opt/homebrew/opt/mysql@8.0/bin:$PATH"
      export LDFLAGS="-L/opt/homebrew/opt/mysql@8.0/lib"
      export CPPFLAGS="-I/opt/homebrew/opt/mysql@8.0/include"
      export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql@8.0/lib/pkgconfig"
      
      # 加载配置
      source ~/.zshrc
  3. 启动服务

    sql 复制代码
    brew services start mysql@8.0
  4. 安全配置

    mysql_secure_installation
    

    配置过程信息

    sql 复制代码
    root@MacBook-Pro ~ % mysql_secure_installation
    
    Securing the MySQL server deployment.
    
    Connecting to MySQL using a blank password.
    
    VALIDATE PASSWORD COMPONENT 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 component?
    # 是否设置密码
    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: 
    
    Estimated strength of the password: 50 
    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) : n
    
     ... 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) : n
    
     ... 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) : y
    Success.
    
    All done! 
    root@MacBook-Pro ~ % 
  5. 连接mysql

    bash 复制代码
    mysql -u root -p
    # 输入密码
相关推荐
醇氧10 分钟前
【MySQL】MySQL 9.0悄悄的来了
数据库·mysql
毛瞌羊11 分钟前
浅析MySQL-索引篇01
数据库·mysql
丁总学Java1 小时前
MySQL高级-MVCC-原理分析(RR级别)
数据库·mysql·mvcc·rr级别·可重复读
“抚琴”的人1 小时前
C#——Path类详情
开发语言·数据库·microsoft·c#
创作小达人1 小时前
InnoDB中的表级锁、页级锁、行级锁详解
java·数据库·mysql
missterzy2 小时前
Spring Boot 创建定时任务
java·数据库·spring boot·定时任务
m0_748171582 小时前
数据库第一次作业
数据库
V+zmm101342 小时前
springcloud分布式架构网上商城 LW +PPT+源码+讲解
java·数据库·后端·vue·idea·springclud
苏生Susheng3 小时前
【Oracle】Oracle常用语句大全
java·数据库·sql·mysql·oracle·sql语句·数据库语法
叶孤程3 小时前
【Qt知识】window frame 对窗口坐标的影响
数据库·qt·microsoft