1> 关闭防火墙和selinux
关闭防火墙
1 service iptables stop 2 chkconfig --level 345 iptables off
关闭selinux
1 setenforce 0 2 cat /etc/SELINUX/config | grep selinux=
查看结果是否为selinux=disabled
2>创建MySQL用户
1 groupadd -g 54330 mysql 3 useradd -u 54330 -g mysql mysql 4 5 7 cd /u01/mysql 9 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 11 tar -xzvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 13 mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql57
15 mkdir mysqldata 17 chown -R mysql:mysql /u01/mysql/
修改root,mysql等用户环境变量
root用户在/root下 .bash_profile
mysql用户在/home/mysql下
1 PATH=$PATH:/u01/mysql/mysql57/bin 2 export PATH
3>修改系统参数
root用户修改参数
1 vi /etc/security/limits.conf 2 mysql soft nproc 16384 3 mysql hard nproc 16384 4 mysql soft nofile 65536 5 mysql hard nofile 65536 6 mysql soft stack 1024000 7 mysql hard stack 1024000
切换到mysql用户
1 su - mysql 2 3 mkdir -p /u01/mysql/mysqldata/3306 4 mkdir -p /u01/mysql/mysqldata/3306/mybinlog 5 mkdir -p /u01/mysql/mysqldata/3306/mydata_1 6 mkdir -p /u01/mysql/mysqldata/3306/mytmp 7 mkdir -p /u01/mysql/mysqldata/3306/mylog
1 su - root 2 chmod +x /u01/mysql/mysql57/bin/mysqld
4> 初始化
1 /u01/mysql/mysql57/bin/mysqld --initialize --user=mysql --basedir=/u01/mysql/mysql57 --datadir=/u01/mysql/mysqldata/3306/mydata --innodb-undo-tablespaces=4
记下密码,后面登陆使用
数据加密
1 /u01/mysql/mysql57/bin/mysql_ssl_rsa_setup --datadir=/u01/mysql/mysqldata/3306/mydata
先root用户赋予权限
1 chown mysql:mysql /etc/my.cnf
登录mysql
配置/etc/my.cnf
1 [client] 2 default-character-set = utf8 3 4 5 [mysql] 6 prompt = [\\u@\\h][\\d]> 7 8 9 [mysqld] 10 basedir = /u01/mysql/mysql57 11 datadir = /u01/mysql/mysqldata/3306/mydata 12 port=3306 13 socket = /u01/mysql/mysqldata/3306/mytmp/mysqld.sock 14 pid_file = /u01/mysql/mysqldata/3306/mysqld.pid 15 tmpdir = /u01/mysql/mysqldata/3306/mytmp/ 16 slave_load_tmpdir = /u01/mysql/mysqldata/3306/mytmp/ 17 log_error = /u01/mysql/mysqldata/3306/mylog/mysqld.log 18 log_bin = /u01/mysql/mysqldata/3306/mybinlog/bin 19 relay_log = /u01/mysql/mysqldata/3306/mybinlog/relay.log 20 server-id=1 21 user=mysql 22 log-slave-updates 23 log-error=mysql1 24 report-host=localhost 25 report-port=3311 26 relay-log-recovery=1 27 master-info-repository=TABLE 28 relay-log-info-repository=TABLE 29 gtid-mode=ON 30 enforce-gtid-consistency=1
5> mysql用户下拉起服务
1 mysqld_safe --defaults-file=/u01/mysql/mysqldata/3306/my.cnf & 2 alter user 'root'@'localhost' identified by '123456';
起停
1 mysqld_safe --defaults-file=/u01/mysql/mysqldata/3306/my.cnf & 2 mysqladmin -uroot -p shutdown