2017-12-25
# 配置主机名完整显示 vim /etc/bashrc # Turn on checkwinsize shopt -s checkwinsize [ "$PS1" = "\s-\v\$ " ] && PS1="[u@H W]\$ " # 配置主机名永久生效 vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=mysql-5.7-master # 配置主机名临时生效 hostname mysql-5.7-master # 配置hosts解析 vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.0.0.156 mysql-5.7-master master 10.0.0.157 mysql-5.7-slave slave # 配置Yum仓库 cd /etc/yum.repos.d wget http://mirrors.163.com/.help/CentOS6-Base-163.repo wget http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm rpm -ivh epel-release-latest-6.noarch.rpm yum clean all && yum makecache # 配置SSH互信 ssh-keygen -t rsa cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys ssh-copy-id slave # 检查残留包 yum list|grep mysql yum -y remove mysql.x86_64 yum -y remove mysql-libs.x86_64 # 删除默认位置配置文件/etc/my.cnf rm -rf /etc/my.cnf # 创建目录 mkdir -p /app/mysql/etc mkdir -p /data/mysql/my3306 # 创建用户 groupadd dba && useradd mysql -g dba # 下载源码包 wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.18.tar.gz # 解压源码包 tar -zxf mysql-boost-5.7.18.tar.gz -C /usr/local/src/ && cd /usr/local/src/mysql-5.7.18 # 安装依赖包 yum -y install ncurses ncurses-devel gcc libtool gcc-c++ make cmake readline-devel zlib-devel bison perl-Module-Install.noarch # 预编译 time cmake -DCMAKE_INSTALL_PREFIX=/app/mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=ON -DWITH_BOOST=/usr/local/src/mysql-5.7.18/boost # 重新编译(可选) make clean rm -rf CMakeCache.txt # 编译、安装 make && make install # 复制配置文件 cp ~/my.cnf /app/mysql/etc/my.cnf ln -s /app/mysql/etc/my.cnf /etc/my.cnf # 修改目录所属组、用户 chown -R mysql.dba /app/mysql/ chown -R mysql.dba /data/mysql/ # 初始化数据库 /app/mysql/bin/mysqld --defaults-file=/app/mysql/etc/my.cnf --initialize --basedir=/app/mysql --datadir=/data/mysql/my3306 --tmpdir=/data/mysql/my3306 --user=mysql # 配置环境变量 vim ~/.bash_profile MYSQL_BASE=/app/mysql PATH=$PATH:$HOME/bin:$MYSQL_BASE/bin source ~/.bash_profile # 配置ssl登录 mysql_ssl_rsa_setup --datadir=/data/mysql/my3306 # 复制启动脚本 cp /app/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld # 启动数据库 service mysqld start # 获取初始化密码 [root@mysql-5.7-master my3306]# grep 'temporary password' /data/mysql/my3306/error.log 2017-12-22T15:39:53.526557Z 1 [Note] A temporary password is generated for root@localhost: bDjk&nU:h2Zl [root@mysql-5.7-slave my3306]# grep 'temporary password' /data/mysql/my3306/error.log 2017-12-25T17:32:27.298337Z 1 [Note] A temporary password is generated for root@localhost: lR(;EGObl8q? # 登录数据库 mysql -uroot -p'bDjk&nU:h2Zl' mysql -uroot -p'lR(;EGObl8q?' # 修改密码并允许其他机器上客户端登录 set global validate_password_policy=0; # 重置root密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'tonghua@789'; grant all privileges on *.* to 'root'@'%' identified by 'tonghua@789' with grant option; # 退出并重新登录数据库 mysql -uroot -p'tonghua@789' # 查看数据库用户及权限 select User,Host,authentication_string,account_locked from mysql.user; # 设置免密码登陆路径 mysql_config_editor set --login-path=my3306 --user=root --password --port=3306 --socket=/data/mysql/my3306/mysql.sock # 查看免密码登陆路径 mysql_config_editor print --all # 删除免密码登陆路径(可选) mysql_config_editor remove --login-path=my3306 # 本地免密码登陆数据库 mysql --login-path=my3306 # 设置开机启动 chkconfig mysqld on chkconfig --list | grep mysql