安装

环境配置

# 修改  ~/.zshrc
vim  ~/.zshrc

# 切换编辑模式
i   

# 添加mysql路径到PATH
export PATH=$PATH:/usr/local/mysql/bin

# 退出vim编辑模式,保存修改
ESC + :wq!

# 使配置生效
soucre  ~/.zshrc

# 别名设置  mysql启动、关闭、重启
alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop'
alias mysqlrestart='sudo /usr/local/mysql/support-files/mysql.server restart'

修改字符集

  • 查看字符集、字序集
# 命令行登录mysql
mysql -uroot -p

# 查看mysql编码
show variables like '%char%';

在 MacOS 里,mysql 一开始就没有 my.cnf 文件,在iterm里,输入:

mysql --help | grep cnf

# 得到

order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
# 新建my.cnf
cd /etc

vim my.cnf

# 新增如下配置

[client]
port = 3306
default-character-set = utf8

[mysqld]
port = 3306
character-set-server = utf8
collation-server = utf8_unicode_ci
init_connect = 'SET NAMES utf8'
default-storage-engine = INNODB

[mysql]
default-character-set = utf8
# 查看mysql编码
show variables like '%char%';

[client] 代表客户端默认设置内容
[mysql] 代表我们使用mysql命令登录mysql数据库时的默认设置
[mysqld] 代表数据库自身的默认设置


luffy9
0 声望0 粉丝