搭建Mysql
1、安装依赖库和工具
## yum -y groupinstall "Development tools"
## yum -y install gcc gcc-c++ libgcrypt openssl openssl098e openssl-devel ncurses ncurses-devel make cmake g++ bison ncurses-libs libaio unzip readline-devel
## yum -y install wget iproute iotop mtr perf telnet dstat iftop vim
2、创建mysql用户
## groupadd -g 306 mysql
## useradd -g mysql -s /sbin/nologin mysql
3、创建tmp目录并将mysql目录持有者修改为mysql
## mkdir /data/mysql/tmp -pv
## chown mysql.mysql /data/mysql -R
4、上传mysql安装包
## cd /root/software
## ls
percona-server-5.6.29-76.2.tar.gz
5、解压mysql
## tar -zxf percona-server-5.6.29-76.2.tar.gz
6、编译安装
## cd percona-server-5.6.29-76.2/
## cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/my.cnf -DMYSQL_TCP_PORT=3306 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLE_DTRACE=0 -DWITH_EXTRA_CHARSETS=all
## make && make install
注: 如果cmake错误,需要重新cmake,需要清除之前的cmake信息:make clean && rm –f CMakeCache.txt
7、初始化
## yum install -y perl-Module-Install.noarch //在CentOS 7.3.1611版本时需要安装,否则初始化会报错
## /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
注:此时初始化完成后会出现一个警告,说服务器已存在/etc/my.cnf,如果不想使用则删除。
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
8、创建my.cnf配置文件目录并上传my.cnf
## mkdir -p /data/conf/mysql
## cd /data/conf/mysql
## ls
my.cnf
9、修改my.cnf
## server_id = 机器IP末位+3306
## innodb-buffer-pool-size = 内存的70%
10、添加变量快捷使用mysql命令
vim /etc/profile
####Mysql####
PATH=$PATH:/usr/local/mysql/bin
export PATH
source /etc/profile
12、启动mysql
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/conf/mysql/my.cnf --user=mysql &
注:若启动不成功查看mysql错误日志进行排错,查看/data/mysql目录是否为mysql用户