MacBookpro安装mysql教程_mac安装mysql的两种⽅法
安装⽅式⼀:⽤dmg镜像安装
1、安装
下载好mysql MAC版安装包,常规步骤安装,安装过程中会出现如下提⽰:
2018-04-22T08:07:19.044013Z 1 [Note] A temporary password is generated for root@localhost: TfrNnt9!k1xi
其中TfrNnt9!k1xi 是初始密码,最好先记住!
2、登陆
但是在终端命令⾏ 登陆mysql
mysql -u root -p
提⽰:-bash: mysql: command not found
遇上-bash: mysql: command not found的情况别着急,这个是因为/usr/local/bin⽬录下缺失mysql导致,只需建⽴软链接,即可以解决:
把mysql安装⽬录,⽐如MYSQLPATH/bin/mysql,映射到/usr/local/bin⽬录下:
cd /usr/local/bin
ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql
接下来登陆就OK啦(完事!)
3、修改密码
在MySQL8.0.4以前,执⾏
SET PASSWORD=PASSWORD('修改的密码');
即可修改密码。
如果mysql是8.0版本以上,这样默认是不⾏的。因为之前,MySQL的密码认证插件是“mysql_native_password”,⽽现在使⽤的
是“caching_sha2_password”。
因为当前有很多数据库⼯具和链接包都不⽀持“caching_sha2_password”,为了⽅便,我暂时还是改回
了“mysql_native_password”认证插件。
在MySQL中执⾏命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
总结:
其实镜像安装⾮常简单,只是在映射mysql指令的时候需要烧点脑⼦。
安装⽅式⼆:⽤Homebrew进⾏安装
最近发现mac上⼀个神奇⼯具 Homebrew(包缺失管理),就像maven管理jar包的依赖⼀样,Homebrew帮忙管理各种⼯具,真是太⽅便。Homebrew的常⽤指令。
安装mysql:brew install mysql
feideMacBook-Air:~ fei$ brew install mysql@5.7
Already downloaded: /Users/fei/Library/Caches/Homebrew/mysql@5.7-5.7.23.high_sierra.
==> Pouring mysql@5.7-5.7.23.high_sierra.
==> /usr/local/Cellar/mysql@5.7/5.7.23/bin/mysqld --initialize-insecure --user=fei ==> Caveats
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 -uroot
This formula is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/mysql@5.7/lib
CPPFLAGS: -I/usr/local/opt/mysql@5.7/include
To have launchd start mysql@5.7 now and restart at login:
brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
/usr/local/Cellar/mysql@5.7/5.7.23: 317 files, 234.4MB
看看输出的提⽰,剩下的该怎么操作其实brew提⽰的很清楚了
对mysql进⾏初始化操作:mysql_secure_installation
cometdeMacBook-Pro:~ comet
$ 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?
// 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
mysql下载安装教程步骤Press y|Y for Yes, any other key for No: N
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
... 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.
// 是否删除test库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y Dropping
Success.
Removing privileges on
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!
OK!这样brew提⽰中的第⼀步就完成!接下来就可以尝试登陆了
登陆mysql:mysql -u root -p
启动mysql:brew services start mysql@5.7停⽌mysql:brew services stop mysql@5.7
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论