安装
步骤1 下载安装
安装:按要求一路安装到底即可。
步骤2 环境变量配置
输入命令,打开文件
vi ~/.bash_profile
贴入下面的语句
export PATH=${PATH}:/usr/local/mysql/bin
按下esc键 ,保存文件并退出
:wq
重置密码
步骤1 关闭MySQL服务
苹果-》系统偏好-》关闭mysql服务;
步骤2 打开iTerm输入命令
//切换目录
cd /user/local/mysql/bin
//取得管理员权限
sudo su
//输入以下命令禁止mysql的验证功能
./mysqld_safe --skip-grant-tables &
//回车输入
./mysql
//切换目录
cd /usr/local/bin/
//回车输入
sudo ln -fs /usr/local/mysql/bin/mysql mysql0
//回车输入
sudo ln -fs /usr/local/mysql/bin/mysql mysql1
最后输入mysql -u root -p 回车就可以输入重置的密码了。
修改MySQL编码格式
步骤1 检查当前数据库编码格式,输入命令
show variables like '%char%';
步骤2 修改mysql的配置文件 my-default.cnf
前提:需要关闭mysql进程。
路径是:/usr/local/mysql/support-files。
如果没有则需要新建一个my-default.cnf文件,修改文件名为my.cnf。
//复制文件到etc目录下
sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
//重新编辑my.cnf文件
sudo vi /etc/my.cnf
[client]部分加入:
default-character-set=utf8
[mysqld]部分加入:
character-set-server=utf8
//保存退出
:wq
重启终端后再查看mysql编码格式就是utf-8了。
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
#备份数据库需要更改的
[mysqldump]
user=root
password=123456
# 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
Windows下MySQL的配置
1、启动/关闭数据库命令:net start mysql,net stop mysql。
2、设置数据库登录不需要密码:
①找到mysql配置环境变量的安装地址。
②打开my.nin文件,加上一句skip-grant-tables,具体位置看截图。