MySQL 8 是mysql的最新版本,它带来了许多改进和新特性,主要新增特性如下:
博主发现自己的mysql版本还停留在5.7,从mysql8导出的数据居然无法导入mysql5.7,于是将mysql版本升级到了8.0,如下是博主的安装记录,供各位同学参考
brew安装
brew install mysql@8.0
安装成功会输出提示:
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配置。
环境配置
查看brew安装mysql得路径
brew --prefix mysql
编辑环境变量,注意修改路径
# 编辑环境变量
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
启动服务
brew services start mysql@8.0
安全配置
mysql_secure_installation
配置过程信息
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 ~ %
连接mysql
mysql -u root -p
# 输入密码