# 下载mysql
$ wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-8.0.13-el7-x86_64.tar.gz
# 解压
$ mysql tar -zxvf mysql-8.0.4-rc-linux-glibc2.12-x86_64.tar.gz -C /usr/local
# 修改文件夹名称
$ mv mysql-8.0.4-rc-linux-glibc2.12-x86_64/ mysql
添加默认配置文件
$ vim/etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
# 创建mysql组
$ groupadd mysql
# 创建mysql用户
$ useradd -g mysql mysql
# 创建mysql数据目录
$ mkdir $MYSQL_HOME/data
# 初始化mysql
$ /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
# 初始化报错
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
# 解决方法
yum install -y libaio
# 初始化报错
2018-07-08T02:53:24.542370Z 0 [System] [MY-010116] /usr/local/mysql/bin/mysqld (mysqld 8.0.4-rc) starting as process 17745 ...
mysqld: Can't create/write to file '/tmp/mysql/data/ibd35qXQ' (Errcode: 13 - Permission denied)
2018-07-08T02:53:24.554816Z 1 [ERROR] [MY-011066] InnoDB: Unable to create temporary file; errno: 13
2018-07-08T02:53:24.554856Z 1 [ERROR] [MY-011066] InnoDB: InnoDB Database creation was aborted with error Generic error. You may need to delete the ibdata1 file before trying to start up again.
2018-07-08T02:53:24.555000Z 0 [ERROR] [MY-010020] Data Dictionary initialization failed.
2018-07-08T02:53:24.555033Z 0 [ERROR] [MY-010119] Aborting
2018-07-08T02:53:24.555919Z 0 [System] [MY-010910] /usr/local/mysql/bin/mysqld: Shutdown complete.
# 解决办法:修改/tmp/mysql的目录权限
$ chown -R mysql:mysql /tmp/mysql
# 初始化成功
> 如果无异常情况日志如下可以看到mysql默认会生成root账号和密码root@localhost: /TI(mjVAs1Ta
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-01-29T10:19:34.023997Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 4240
2019-01-29T10:19:39.764895Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /TI(mjVAs1Ta
2019-01-29T10:19:43.041419Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed
# 拷贝mysql启动文件到系统初始化目录
$ cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 启动mysql服务器
$ service mysqld start
mysql基本操作
# 使用mysql客户端连接mysql
$ /usr/local/mysql/bin/mysql -u root -p password
修改mysql的默认初始化密码
> alter user 'root'@'localhost' identified by 'root';
# 创建用户 CREATE USER '用户名称'@'主机名称' INDENTIFIED BY '用户密码'
> create user 'jack'@'localhost' identified by 'jack';
# 授予权限 grant 权限 on 数据库.表 to '用户名'@'登录主机' [INDENTIFIED BY '用户密码'];
> grant replication slave on *.* to 'jack'@'localhost';
# 刷新
# $ flush privileges;
# 修改root用户可以远程连接
> update mysql.user set host='%' where user='root';
# 查看mysql所用用户
> select user,host from mysql.user;
# docker 修改mysql的最大连接数
apt-get update
apt-get install vim
vim /etc/mysql/mysql.conf.d/mysqld.cnf
max_connections=1000
> alter user 'root'@'%' identified with mysql_native_password by 'root';
mysql 主从复制
# 配置主服务添加如下配置
$ vim /etc/my.cnf
# 节点唯一id值
server-id=1
# 开启二进制日志
log-bin=mysql-bin
# 指定日志格式 有mixed|row|statement 推荐mixed
binlog-format=mixed
# 步进值auto_imcrement。一般有n台主MySQL就填n(可选配置)
auto_increment_increment=2
# 起始值。一般填第n台主MySQL。此时为第一台主MySQL(可选配置)
auto_increment_offset=1
# 忽略mysql库(可选配置)
binlog-ignore=mysql
# 忽略information_schema库(可选配置)
binlog-ignore=information_schema
# 要同步的数据库,默认所有库(可选配置)
replicate-do-db=db1
# slave 节点配置
# 节点唯一id值
server-id=2
# 开启二进制日志
log-bin=mysql-bin
# 步进值auto_imcrement。一般有n台主MySQL就填n(可选配置)
auto_increment_increment=2
# 起始值。一般填第n台主MySQL。此时为第一台主MySQL(可选配置)
auto_increment_offset=2
# 要同步的数据库,默认所有库(可选配置)
replicate-do-db=db1
# 查看 master 的状态 , 尤其是当前的日志及位置
> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000004 | 1608 | | | |
+------------------+----------+--------------+------------------+-------------------+
# 在slave节点执行如下命令
注意master_log_file 是对应show master status;中file的值,master_log_pos是对应position的值
> change master to
master_host='192.168.79.15',
master_user='root',
master_password='root',
master_log_file='mysql-bin.000009',
master_log_pos=0;
# 启动 slave 状态 ( 开始监听 msater 的变化 )
> start slave;
# 查看 slave 的状态
> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.79.15
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 863
Relay_Log_File: node-6-relay-bin.000002
Relay_Log_Pos: 500
Relay_Master_Log_File: mysql-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 863
Relay_Log_Space: 709
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 6291c709-23af-11e9-99fb-000c29071862
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
# 当Slave_IO_Running: Yes和Slave_SQL_Running: Yes都为yes是说明主从复制正常
#重置 slave 状态 .
$ reset slave;
#暂停 slave 状态 ;
$ stop slave;