赞
踩
本文为博主原创,若转载请注名出处。
在Mac上安装homebrew(官网安装教程)
homebrew依赖:Command Line Tools (CLT) for Xcode或者Xcode这两者 的安装就不细说了在准备好以上工具后在terminal输入:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
关于使用homebrew的使用在这里不做介绍
确认安装成功
在terminal输入:
brew doctor
使用homebrew安装mysql
在terminal输入:
brew install mysql
homebrew的配置
使用mysql的配置脚 本:/usr/local/opt/mysql/bin/mysql_secure_installation 启动这个脚本后,即可根据如下命令提示进行初始化设置(在这之前先启动mysql服务)
sunyichaodeMacBook-Pro:~ sunyichao$ /usr/local/opt/mysql/bin/mysql_secure_installation //mysql 提供的配置向导
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwordsand 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?
Press y|Y for Yes, any other key for No: k //是否采用mysql密码安全检测插件(这里作为演示选择否,密码检查插件要求密码复杂程度高,大小写字母+数字+字符等)
Please set the password for root here. // 首次使用自带配置脚本,设置root密码
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 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? [Y/n] 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? [Y/n] Y //是否禁止远程登录
... Success!
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.
Remove test database and access to it? [Y/n] Y //删除测试数据库,并登录
Dropping test database...
... Success!
Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y//重新载入权限表
... Success!
All done!
接下来我们在terminal中启动mysql服务:
brew services start mysql
进入mysql命令行:
mysql -u root -p (接下来输入密码)
成功进入mysql命令行之后查看当前编码格式:
show variables like "%char%"
为了避免一些麻烦编码需要修改。我们先停掉mysql服务:
exit
brew services stop mysql
mysql的全局配置文件在my.cnf文件里面,可是问题来了,mysql5.6或者5.7安装目录下已经没有这个文件了,但是有一个my-defalut.cnf的文件.打开看看:
第二行已经告诉了我们解决问题的方法在:
http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
创建my.cnf 文件将以下内容复制进去
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id = 1
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
# binary logging format - mixed recommended
#binlog_format=mixed
# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
那么这个文件保存在哪里呢?
打开terminal输入:
mysql --help
你会找到:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
默认的设置会按下面按顺序给出来文件夹中的my.cnf文件读取所以我们就直接将my.cnf放在/etc下面(这是个隐藏文件夹在terminal中输入:defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder 即可显示隐藏文件,若想改回来把true改为false再次输入运行即可)
再次检查mysql编码问题:
进入mysql shell之后输入:
show variables like "%char%";
若有错误请留言告知,谢谢
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。