Macos下安装MySQL简明教程
程序员文章站
2022-05-28 16:27:15
...
环境介绍
Macos Jave 10.14. MySQL 5.7
基于Brew安装
brew install [email protected]
运行结果如下:
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/[email protected]
######################################################################## 100.0%
==> Pouring [email protected]
==> /usr/local/Cellar/[email protected]/5.7.24/bin/mysqld --initialize-insecure --user=chenjunfeng1 --basedir=/usr/local/Cellar/[email protected]/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
[email protected] 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 [email protected] first in your PATH run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
For pkg-config to find [email protected] you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
To have launchd start [email protected] now and restart at login:
brew services start [email protected]
Or, if you don't want/need a background service you can just run:
/usr/local/opt/[email protected]/bin/mysql.server start
==> Summary
? /usr/local/Cellar/[email protected]/5.7.24: 317 files, 234.3MB
查看当前MySQL的安装情况
brew info [email protected]
命令的输出结果如下:
[email protected]: 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/[email protected]/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/[email protected]
==> 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
[email protected] 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 [email protected] first in your PATH run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
For pkg-config to find [email protected] you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
To have launchd start [email protected] now and restart at login:
brew services start [email protected]
Or, if you don't want/need a background service you can just run:
/usr/local/opt/[email protected]/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 [email protected]
==> Successfully started `[email protected]` (label: [email protected])
启动MySQL
brew services start [email protected]
启动过程信息如下:
==> Successfully started `[email protected]` (label: [email protected])
查看启动的service list
brew services list
查看服务的列表结果输出:
Name Status User Plist
emacs stopped
[email protected] started chenjunfeng1 /Users/username/Library/LaunchAgents/[email protected]
将当前的MySQL强制指向5.7
brew link [email protected] --force
信息输出如下:
Linking /usr/local/Cellar/[email protected]/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/[email protected]/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
上一篇: linux下OpenMVG编译简明教程