- brew安装mysql">brew安装mysql
- http://dev.mysql.com/doc/mysql/en/option-files.html">http://dev.mysql.com/doc/mysql/en/option-files.html
- mysql —help
- password = your_password
- Don’t listen on a TCP/IP port at all. This can be a security enhancement,
- skip-networking
- log-bin=/var/log/mysql/mysql-bin
- 复制从机(注释掉主部分以使用此功能)
- 第一种方法:
- 使用CHANGE MASTER TO命令(在我们的手册中有详细描述)-语法为:
- CHANGE MASTER TO MASTER_HOST=
, MASTER_PORT= , - MASTER_USER=
, MASTER_PASSWORD= ; - Example:
- CHANGE MASTER TO MASTER_HOST=’125.564.12.1’, MASTER_PORT=3306,
- MASTER_USER=’joe’, MASTER_PASSWORD=’secret’;
- 第二种方法:
- 如果设置了主主机,则默认为2
- server-id = 2
- 此从机的复制主机-必需
- master-host =
- 连接时从属服务器将用于身份验证的用户名,to the master - required
- master-user =
- 从机连接到时将使用的密码,to the master - required
- master-password =
- 主机正在监听的端口,可选-默认为3306
- master-port =
- 二进制日志记录-不需要从服务器,但建议
- log-bin=mysql-bin
- 如果使用InnoDB表,请取消注释以下内容
- innodb_data_home_dir = /usr/local/mysql/data
- innodb_data_file_path = ibdata1:10M:autoextend
- innodb_log_group_home_dir = /usr/local/mysql/data
- innodb_buffer_pool_size = 16M
- innodb_additional_mem_pool_size = 2M
- innodb_log_file_size = 5M
- innodb_log_buffer_size = 8M
- innodb_flush_log_at_trx_commit = 1
- innodb_lock_wait_timeout = 50
- Remove the next comment character if you are not familiar with SQL
- safe-updates
brew安装mysql
1.使用brew安装mysql
brew install mysql
启动
2.启动mysql服务
方式1: brew services start mysql (推荐)
方式2: mysql.server start
#重启
方式1: brew services restart mysql
方式2: mysql.server restart
#配置launchctl自启动
方式1:
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
find /usr/local/Cellar/mysql/ -name "homebrew.mxcl.mysql.plist" -exec cp {} ~/Library/LaunchAgents/ \;
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
方式2:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
初始化
mysql_secure_installation
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG 请输入0=低,1=中,2=强
关闭与卸载
#关闭停止
方式1: mysql.server stop
方式2: brew services stop mysql
#卸载
brew uninstall mysql
#彻底清除残支
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
查看
#查看状态
mysql.server status 或 ps -ef|grep mysqld
#查看所有可由Homebrew管理的服务
brew services list
#查看帮助
mysql --help 或 mysql -?
创建my.cnf配置文件
- 首先需要知道系统是按如下顺序去找my.cnf:
i. /etc/my.cnf
ii. /etc/mysql/my.cnf
iii. /usr/local/etc/my.cnf
iv. ~/.my.cnf
- 所以就在/etc下创建my.cnf,sudo vim /etc/my.cnf
```bash
http://dev.mysql.com/doc/mysql/en/option-files.html
mysql —help
[client] default-character-set=utf8
password = your_password
port = 3306 socket = /tmp/mysql.sock
[mysqld] character-set-server=utf8 init_connect=’SET NAMES utf8 port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M character-set-server=utf8 secure_file_priv=’’ init_connect=’SET NAMES utf8’
Don’t listen on a TCP/IP port at all. This can be a security enhancement,
skip-networking
log-bin=mysql-bin
log-bin=/var/log/mysql/mysql-bin
binlog_format=mixed
server-id = 1
复制从机(注释掉主部分以使用此功能)
第一种方法:
使用CHANGE MASTER TO命令(在我们的手册中有详细描述)-语法为:
CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,
MASTER_USER=, MASTER_PASSWORD= ;
Example:
CHANGE MASTER TO MASTER_HOST=’125.564.12.1’, MASTER_PORT=3306,
MASTER_USER=’joe’, MASTER_PASSWORD=’secret’;
第二种方法:
如果设置了主主机,则默认为2
server-id = 2
#
此从机的复制主机-必需
master-host =
连接时从属服务器将用于身份验证的用户名,to the master - required
master-user =
从机连接到时将使用的密码,to the master - required
master-password =
主机正在监听的端口,可选-默认为3306
master-port =
二进制日志记录-不需要从服务器,但建议
log-bin=mysql-bin
如果使用InnoDB表,请取消注释以下内容
innodb_data_home_dir = /usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
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
default-character-set=utf8
[myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M
[mysqlhotcopy] interactive-timeout
<a name="MWzlp"></a>
### 简易安装
<a name="DXfpa"></a>
#### 下载安装包
> 首先去官网下载mac版的mysql,链接如下:[MySql下载](https://dev.mysql.com/downloads/mysql/)
<a name="eZyTR"></a>
#### 设置全局变量
```bash
#设置暂时性全局变量
export PATH=$PATH:/usr/local/git/bin
#设置永久性全局变量 vim ~/.bash_profile 或者 vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin
使用永久性全局变量别忘了使文件生效 source ~/.bash_profile 或 source /etc/profile
连接远程
mysql -h 119.23.72.172 -uroot -pQwer@1234
问题
警告:全局可写配置文件’/etc/mysql/my.cnf’被忽略
[Warning] World-writable config file ‘/usr/local/etc/my.cnf’ is ignored.
chmod 644 /etc/my.cnf && chmod 644 /usr/local/etc/my.cnf
用户“root”@“localhost”的访问被拒绝(使用密码:否)
Access denied for user ‘root’@’localhost’ (using password: NO)
1、先停掉原来的服务
方法一: brew services stop mysql
方法二: kill -9 <pid>
2、使用安全模式登陆,跳过密码验证
方法一(推荐):使用一个窗口运行下面这行代码,然后打开【新的shell窗口】操作步骤3
mysqld_safe --user=mysql --skip-grant-tables --skip-networking&
方法二:vim /etc/my.cnf ,在配置文件中加入下面这行代码,保存并重启mysql服务,然后打开【新的shell窗口】操作步骤3
skip-grant-tables
3、进入mysql,修改密码:
mysql -u root -p #连接mysql服务,不要输入密码,两次回车进入
select version(); #查看版本号
flush privileges; #刷新权限
alter user'root'@'localhost' IDENTIFIED BY 'aBc@123456'; # 注意: mysql8.0以上密码策略限制必须要大小写加数字特殊符号
flush privileges; #再次刷新权限
4.重启mysql登陆测试
按「步骤1方法二」需要: 把添加的 skip-grant-tables 删除或注释
brew services start mysql
Failed to start mysqld.service: Unit mysqld.service not found.
启动mysqld.service失败:找不到命令行mysqld.service,安装没有成功
mysql -h 119.23.72.172 -uroot -pQwer@1234