yum -y install perl-Module-Install.noarch将我们下载的文件拷贝到我的目录下:
yum -y install libaio libaio-devel
yum -y install gcc gcc-c++ make cmake automake autoconf libxml2 libxml2-devel zlib zlib-devel ncurses ncurses-devel
[root@mxqmongodb2 sa]# ls创建用户和必要文件夹:
autokey maxiangqian.txt mxq.txt mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz redis-3.2.8.tar.gz redis-3.2.8.tar.gz.1
[root@mxqmongodb2 sa]# cd /home/maxiangqian/
[root@mxqmongodb2 maxiangqian]# cp /home/sa/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz /home/maxiangqian/
[root@mxqmongodb2 maxiangqian]# ls
mongodb-linux-x86_64-rhel62-3.4.2 mongodb-linux-x86_64-rhel62-3.4.2.tgz mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz redis-3.2.8 redis-3.2.8.tar.gz
[root@mxqmongodb2 maxiangqian]# mkdir -p /home/mysql/db3306/{data,log,tmp}现在我们已经创建好了数据库的基本的需求,下面解压:
[root@mxqmongodb2 maxiangqian]# groupadd mysql
[root@mxqmongodb2 maxiangqian]# useradd -r -g mysql -s /bin/false mysql
[root@mxqmongodb2 mysql]# cd /home/mysql/
[root@mxqmongodb2 mysql]# ls
db3306
[root@mxqmongodb2 mysql]# tar zxvf /home/maxiangqian/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
[root@mxqmongodb2 mysql]# ls
db3306 mysql-5.7.14-linux-glibc2.5-x86_64
授权以及创建软连接:
[root@mxqmongodb2 mysql]# ln -s /home/mysql/mysql-5.7.14-linux-glibc2.5-x86_64/ /usr/local/mysql
[root@mxqmongodb2 mysql]# chown -R mysql:mysql /usr/local/mysql/
[root@mxqmongodb2 mysql]# chown -R mysql:mysql /home/mysql/
创建配置文件:
[root@mxqmongodb2 mysql]# vi /home/mysql/db3306/my3306.cnf
配置文件的内容贴在最后。
初始化MySQL:[root@mxqmongodb2 mysql]# /usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/db3306/my3306.cnf --initialize --user='mysql' --log_error_verbosity --explicit_defaults_for_timestamp
[root@mxqmongodb2 mysql]# mysqld_safe --defaults-file=/home/mysql/db3306/my3306.cnf &
[1] 4932
[root@mxqmongodb2 mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
[root@mxqmongodb2 mysql]# source /etc/profile
然后我们去看一下进程,并且登录到MySQL:
[root@mxqmongodb2 mysql]# ps -ef|grep mysql
root 4932 4852 0 10:41 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/db3306/my3306.cnf
mysql 5502 4932 0 10:41 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/db3306/my3306.cnf --basedir=/usr/local/mysql --datadir=/home/mysql/db3306/data/ --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/home/mysql/db3306/log/mysql-error.log --pid-file=/home/mysql/db3306/tmp/mysqld.pid --socket=/home/mysql/db3306/tmp/mysql.sock --port=3306
root 5533 4852 0 10:42 pts/0 00:00:00 grep mysql
[root@mxqmongodb2 mysql]# cat /home/mysql/db3306/log/mysql-error.log |grep passw
2017-05-10T02:40:52.028140Z 1 [Note] A temporary password is generated for root@localhost: Y,?szysAN2tV
[root@mxqmongodb2 mysql]# cd /home/mysql/db3306/tmp/
[root@mxqmongodb2 tmp]# ls
mysqld.pid mysql.sock mysql.sock.lock
[root@mxqmongodb2 tmp]# mysql -S /home/mysql/db3306/tmp/mysql.sock -p
登录成功修改密码:
mysql> set password=password('maxiangqianmysql');
Query OK, 0 rows affected, 1 warning (0.04 sec)
安装完毕
下面我们配置一下双主结构吧,随便附加点东西,基于我们两台服务器已经安装好了MySQL5.7.14两边建立复制账号:GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* to 'repl'@'172.16.16.%' identified by 'replication';
flush privileges;
打开复制:
SERVER2:
CHANGE MASTER TO MASTER_HOST='172.16.16.34', MASTER_USER='repl', MASTER_PASSWORD='replication', MASTER_PORT=3306, master_auto_position=1;
SERVER1:
CHANGE MASTER TO MASTER_HOST='172.16.16.35', MASTER_USER='repl', MASTER_PASSWORD='replication', MASTER_PORT=3306, master_auto_position=1;
两台主机:
START SLAVE;
SHOW SLAVE STATUS\G
发现没有问题,接下来验证双主复制:
server1:
root@mysql03:52:00>create database maxiangqian;
Query OK, 1 row affected (0.08 sec)
server2:
mysql> use maxiangqian
Database changed
mysql> create table maxiangqian(id int );
Query OK, 0 rows affected (0.26 sec)
server1:
root@mysql03:54:37>select * from maxiangqian .maxiangqian;
+------+
| id |
+------+
| 111 |
+------+
1 row in set (0.00 sec)
也可以SHOW SLAVE STATUS\G来看一下复制状态
可见双主复制是成功的。 再附件一个MySQL的常识-MySQL连接方式:MySQL的连接方式分为TCP/IP和socket的方式链接本机登录MySQL在不指定-h的前提下是默认socket链接,比如:msyql -uroot -p或者我们可以显示指定socket链接:mysql -uroot -S /home/mysql/tmp/mysql,scok -p默认情况下会先找/tmp/mysql.scok,如果我们的my.cnf李client指定了socket文件的位置的话。客户端默认先去找配置的位置。而且mysql client只会通过/etc/my.cnf读取client的基本配置。client读取配置文件的顺序是:/etc/my.cnf -----/etc/mysql/my.cnf------/usr/local/mysql/etc/my.cnf ----~/my.cnf指定-h以后就默认为TCP/IP链接。