1.下载mysql的Mac版本。推荐使用最新的8.0
https://dev.mysql.com/downloads/mysql/
下载mysql-8.0.24-macos11-x86_64.dmg
注意:
需要基于电脑的OS版本(通过《关于本机》查看),选择合适的dmg版本,如果是os不是最新的,可以从archives里面找对应的版本。
安装
2. 安装mysql
在安装过程中有一点需要注意的就是密码设置也就是下图, 第一个选项是使用8.0版本才有的密码加密方式。第二个选项是沿用5.7版本的密码加密方式。此两种选项第一种有可能会出现Navicat不支持该加密方式的情况出现。所以建议大家还是先选中第二种。
///我选的第一种
//输入密码,这个密码后面登陆mysql会用到。
双击进入mysql,
勾掉随电脑自动启动,点击stop MYSQL server按钮停掉进程。
3.环境变量和权限设置:
添加读写权限:
sudo chmod -R a+rwx /usr/local/mysql/data/
添加环境变量:
EthanNi-MacBook-Pro:~ candy$ vi .bash_profile
添加两行
export PATH=
P
A
T
H
:
/
u
s
r
/
l
o
c
a
l
/
m
y
s
q
l
/
b
i
n
a
l
i
a
s
m
y
s
q
l
=
"
m
y
s
q
l
−
u
r
o
o
t
−
p
"
添
加
后
查
看
文
件
:
E
t
h
a
n
N
i
−
M
a
c
B
o
o
k
−
P
r
o
:
c
a
n
d
y
{PATH}:/usr/local/mysql/bin alias mysql="mysql -u root -p" 添加后查看文件: EthanNi-MacBook-Pro:~ candy
PATH:/usr/local/mysql/binaliasmysql="mysql−uroot−p"添加后查看文件:EthanNi−MacBook−Pro: candy cat .bash_profile
export PATH=${PATH}:/usr/local/bin
export PATH=${PATH}:/usr/local/mysql/bin
elias python2="/user/local/bin/python"
alias python="/usr/local/bin/python3"
alias mysql="mysql -u root -p"
EthanNi-MacBook-Pro:~ candy$ exit
这样以后输入mysql就能直接进入输入密码的步骤了。
4.进程起停
终端启停mysql
启动MySQL服务 sudo /usr/local/MySQL/support-files/mysql.server start
停止MySQL服务 sudo /usr/local/mysql/support-files/mysql.server stop
重启MySQL服务 sudo /usr/local/mysql/support-files/mysql.server restart
—启动mysql
EthanNi-MacBook-Pro:support-files candy$ ./mysql.server start
Starting MySQL
… SUCCESS!
EthanNi-MacBook-Pro:support-files candy$ ./mysql.server status
SUCCESS! MySQL running (40889)
成功启动的日志:
2021-04-22T02:48:51.6NZ mysqld_safe Logging to ‘/usr/local/mysql/data/EthanNi-MacBook-Pro.local.err’.
2021-04-22T02:48:51.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2021-04-22T02:48:52.416206Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.24) starting as process 40889
2021-04-22T02:48:52.458690Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2021-04-22T02:48:52.555873Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-22T02:48:53.022596Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-04-22T02:48:53.265123Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: ‘::’ port: 33060, socket: /tmp/mysqlx.sock
2021-04-22T02:48:53.296442Z 0 [Warning] [MY-000054] [Server] World-writable config file ‘./auto.cnf’ is ignored.
2021-04-22T02:48:53.297337Z 0 [Warning] [MY-010107] [Server] World-writable config file ‘./auto.cnf’ has been removed.
2021-04-22T02:48:53.298302Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 463d19d6-a315-11eb-9e9d-1267ced3b616.
2021-04-22T02:48:53.428525Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-04-22T02:48:53.428989Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-04-22T02:48:53.437686Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location ‘/usr/local/mysql/data’ in the path is accessible to all OS users. Consider choosing a different directory.
2021-04-22T02:48:53.537829Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: ‘8.0.24’ socket: ‘/tmp/mysql.sock’ port: 3306 MySQL Community Server - GPL.
5.登陆mysql
重新登陆mysql:
EthanNi-MacBook-Pro:~ candy$ mysql
ERROR 1045 (28000): Access denied for user ‘candy’@‘localhost’ (using password: NO)
日志如下:
2021-04-22T02:57:01.297579Z 8 [Warning] [MY-013360] [Server] Plugin sha256_password reported: '‘sha256_password’ is deprecated and will be removed in a future release. Please use caching_sha2_password instead’
EthanNi-MacBook-Pro:~ candy$ mysql -u root -p
Enter password: ——comment by Ethan:输入安装configuration步骤时输入的root密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.24 MySQL Community Server - GPL
Copyright © 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>