😀 通过brew安装mysql@8.0
前言
MySQL 8 是mysql的最新版本,它带来了许多改进和新特性,主要新增特性如下:
-
公用表表达式(CTE) : CTE 可以简化复杂的 JOIN 查询和子查询,并支持递归查询,提高 SQL 的可读性和执行性能。
-
默认字符集变更 : 默认字符集由 latin1 变为 utf8mb4,utf8 也默认指向 utf8mb4,支持更多的 Unicode 字符。
-
克隆插件 : 提供了从一个实例克隆出另一个实例的功能,有助于快速创建 MySQL 实例和搭建复制环境。
-
资源组 : 允许调控线程优先级和绑定 CPU 核,需要相应的权限和系统支持。
-
角色管理 : 角色可以看作是权限的集合,简化了权限管理。
-
参数修改持久化 : 支持在线修改全局参数并持久化到配置文件中。
-
InnoDB 锁等待改进 : 新增 NOWAIT 和 SKIP LOCKED 语法,允许跳过锁等待。
-
GROUP BY 排序行为变更 : 为了兼容 SQL 标准,不再隐式排序。
-
自适应参数 : 自动调整参数以适应服务器的硬件配置。
-
窗口函数 : 从 MySQL 8.0 开始,引入了窗口函数,提供了新的查询方式。
-
性能提升 : 官方表示 MySQL 8.0 的性能是 MySQL 5.7 的两倍,特别是在读/写工作负载、IO 密集型工作负载和高竞争工作负载方面。
-
JSON 扩展 : 提供了更多的 JSON 功能,包括 JSON 表函数和聚合函数。
-
GIS 地理支持 : 增强了对地理信息系统的支持。
-
DDL 原子性和崩溃安全 : 改进了数据定义语言的可靠性。
-
性能架构改进 : 提升了性能架构的可观察性。
-
安全增强 : 包括 OpenSSL 改进、新的默认身份验证、SQL 角色等。
-
错误日志改进 : 错误日志系统进行了重大改进,提供了更多的灵活性和自定义选项。
-
可管理性增强 : 包括撤销表空间管理、全局变量持久化等。
-
远程管理 : 通过 SQL RESTART 命令等实现远程管理。
博主发现自己的mysql版本还停留在5.7,从mysql8导出的数据居然无法导入mysql5.7,于是将mysql版本升级到了8.0,如下是博主的安装记录,供各位同学参考
📝 主旨内容
-
brew安装
cssbrew install mysql@8.0
安装成功会输出提示:
vbnetWe'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配置。
-
环境配置
-
查看brew安装mysql得路径
cssbrew --prefix mysql
-
编辑环境变量,注意修改路径
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
-
-
启动服务
sqlbrew services start mysql@8.0
-
安全配置
mysql_secure_installation
配置过程信息
sqlroot@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 ~ %
-
连接mysql
bashmysql -u root -p # 输入密码