MacBook安装Mysql

MacBook安装Mysql

Mysql官方下载地址: https://dev.mysql.com/downloads/mysql/

官方下载 MySQL Community Server 社区版
选择对应的版本和系统下载: mysql-5.7.22-macos10.13-x86_64.dmg
点击安装 注意安装过程会弹出 密码 需要记住密码
在设置里最下面找到mysql 打开后启动,这里我把开机自动启动给去掉了

#Mysql命令添加到环境变量里
vim ~/.zshrc 
#最后加入 
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH

#使配置生效 
source ~/.zshrc

#查看mysql版本
mysql —version

#修改密码
mysql -u root -p
#输入之前保存的密码

#设置新密码 如:123456
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('123456');

#设置远程连接授权
grant all privileges on *.* to 'root'@'%' identified by '123456';

flush privileges;

#修改mysql配置  查看编码
show variables like '%char%';

#新版本的mysql 安装目录下没有默认配置文件了 /usr/local/mysql/support-files  可以从其他地方复制一份过来

mysql配置文件

sudo vim /etc/my.cnf
#查看配置
cat my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET  NAMES utf8mb4'

basedir = /data/soft/mysql-5.7.16
datadir = /data/datas/mysql/data

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

port = 3306
server_id = 212
binlog-ignore-db = mysql,sys,information_schema,performance_schema
log-bin = mysql-bin

max_binlog_size = 500M
binlog_cache_size = 2M
max_binlog_cache_size = 4M
expire_logs_days = 30
max_connections = 500
max_connect_errors = 10000
table_open_cache = 256
long_query_time = 1
slow-query-log
slow_query_log_file = /data/datas/mysql/data/slow_query_log_file.log

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

#timezone='UTC'

#修改完后重启mysql服务
#再次查看编码
show variables like '%char%';

参考链接:
https://blog.csdn.net/catstarxcode/article/details/78940385
https://www.jianshu.com/p/a8e4068a7a8a
https://www.jianshu.com/p/438bbcd26bea
https://blog.csdn.net/u010281209/article/details/53965409

你可能感兴趣的:(mysql,mysql,macbook)