Macos下安装MySQL简明教程

环境介绍

Macos Jave 10.14. MySQL 5.7

基于Brew安装

brew install mysql@5.7

运行结果如下:

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.24.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql@5.7-5.7.24.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.24/bin/mysqld --initialize-insecure --user=chenjunfeng1 --basedir=/usr/local/Cellar/mysql@5.7/5.7.24 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> 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

mysql@5.7 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 mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"

For pkg-config to find mysql@5.7 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/mysql@5.7/lib/pkgconfig"

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.24: 317 files, 234.3MB

查看当前MySQL的安装情况

brew info mysql@5.7

命令的输出结果如下:

mysql@5.7: stable 5.7.24 (bottled) [keg-only]
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
/usr/local/Cellar/mysql@5.7/5.7.24 (317 files, 234.3MB)
  Poured from bottle on 2018-10-29 at 09:50:32
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql@5.7.rb
==> Dependencies
Build: cmake ✘
Required: openssl ✔
==> Requirements
Required: macOS >= 10.7 ✔
==> Options
--with-embedded
	Build the embedded server
--with-local-infile
	Build with local infile loading support
--with-memcached
	Build with InnoDB Memcached plugin
==> 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

mysql@5.7 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 mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"

For pkg-config to find mysql@5.7 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/mysql@5.7/lib/pkgconfig"


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
==> Analytics
install: 21,701 (30 days), 61,998 (90 days), 93,106 (365 days)
install_on_request: 21,647 (30 days), 61,858 (90 days), 92,927 (365 days)
build_error: 0 (30 days)

MySQL安装Brew Services

安装brew services

brew tap homebrew/services
命令输出结果为:

Updating Homebrew...
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 0), reused 9 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
Tapped 1 command (44 files, 58.6KB).
hostmachine:~ forkusername$ brew services start mysql@5.7
==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)

启动MySQL

brew services start mysql@5.7
启动过程信息如下:

==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)

查看启动的service list

brew services list
查看服务的列表结果输出:

Name      Status  User         Plist
emacs     stopped              
mysql@5.7 started chenjunfeng1 /Users/username/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist

将当前的MySQL强制指向5.7

brew link mysql@5.7 --force

信息输出如下:

Linking /usr/local/Cellar/mysql@5.7/5.7.24... 87 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

检查当前MySQL的版本

mysql -V

版本信息输出如下:

mysql  Ver 14.14 Distrib 5.7.24, for osx10.14 (x86_64) using  EditLine wrapper

配置MySQL

设置root密码

mysqladmin -u root password ‘password’

输出结果信息:

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

登陆MySQL,创建表

mysql -u root -p ‘password’
show databases;
create database ‘db_name’;
use db_name;

总结

在Macos下,主要是使用brew来进行系统的配置和管理的。

Reference

  1. https://gist.github.com/operatino/392614486ce4421063b9dece4dfe6c21
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值