一. 快速进入mysql命令行
1.终端输入进入bin目录
$ cd /usr/local/mysql/bin/
2. mysql 登录,输入密码即可
$ ./mysql -u root -p
注意:mysql 服务必须是启动的状态
二. mysql 修改编码格式
1. 进入mysql,使用$ SHOW VARIABLES LIKE 'char%'; 查看查看当前编码格式,mysql默认使用的是拉丁文。
character_set_server依然是latin1的字符集,不是utf8格式,会造成很多麻烦。(我导入的项目就是因为这个原因找了两天o(╥﹏╥)o)
2.需要修改编码,那就需要修改mysql的配置文件 my.cnf
注意:在修改my.cnf 的时候一定要关闭mysql进程,不然就会遇到不能连接的问题!
mac安装 mysql 默认是没有my.cnf 文件的!
所以我们需要到mysql的安装目录下看看有没有.cnf为后缀的文件(我没有这个文件)。安装目录为/mysql/support-files/ 下会有一个my-default.cnf文件,然后复制他它!
3. 如果有my-default.cnf 文件就把文件粘贴到/etc 这个目录下。
然后打开编辑my.cnf,然后再
[mysqld] 下面加入:character-set-server=utf8
如果没有my-default.cnf 文件,在/etc文件夹下创建一个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.
#更改数据库编码需要更改的
[mysqld]
character-set-server=utf8
# 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 = .....
# 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
4. 重新启动 mysql, 查看编码
网友评论