1、打开mac控制台mysql
brew install mysql@5.7 复制代码
修改环境变量复制代码
vi ~/.zshrc
export PATH=${PATH}:/usr/local/Cellar/mysql@5.7/5.7.24/bin
source ~/.zshrc复制代码
2、启动mysql服务git
mysql.server start复制代码
3、初始化mysql配置sql
mysql_secure_installation复制代码
WXiangQianMacBook-Pro:~ wxq$ mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN 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 plugin?
Press y|Y for Yes, any other key for No: N // 这个选yes的话密码长度就必需要设置为8位以上,但我只想要6位的
Please set the password for root here.
New password: // 设置密码
Re-enter new password: // 再一次确认密码
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 //不接受root远程登陆帐号
... 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) : y //删除text数据库
- 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? (Press y|Y for Yes, any other key for No) : y
Success.
All done!复制代码
设置密码时提示:ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number;数据库
使用其余语句时, 老是会提示 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement. 意思就是说必须先设置一个密码bash
而设定密码时又提示 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number ;ui
这是由于 你输入的密码是明文, 不容许这么输入. 能够在其余已安装过mysql的终端使用 select password('你想输入的密码');查询出你的密码对应的字符串, 而后用这个字符串替换你的密码.this
这样mysql就安装成功了spa
mysql -u root -p 输入密码之后i就能够正常进入了code