yum install gcc gcc-c++ bzip2-devel bzip2-libs python-devel ncurses-devel bison perl-Module-Install.noarch -y
cd /usr/local/src/
wget "http://distfiles.macports.org/cmake/cmake-3.6.2.tar.gz"
tar -zxvf cmake-3.6.2.tar.gz
cd cmake-3.6.2
./bootstrap
gmake && gmake install
cd ..
wget "http://mirror.neu.edu.cn/mysql/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz"
tar -zxvf mysql-5.6.27.tar.gz
cd mysql-5.6.27
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.27 \-DMYSQL_DATADIR=/data/mysql/ \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \-DMYSQL_TCP_PORT=4568 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci
make && make install
创建mysql目录级修改权限
groupadd mysql
useradd -M -s /sbin/nologin -g mysql mysql
mkdir -p /data/mysql/data
mkdir -p /data/mysql/log
chown mysql:mysql -R /data/mysql/
主配置
vi /etc/my.cnf
[client]port = 4568socket = /data/mysql/log/mysql.sock[mysqld]user = mysqlport = 4568character-set-server = utf8default-storage-engine = InnoDBsocket = /data/mysql/log/mysql.sockpid-file = /data/mysql/log/mysql.pid# DATA STORAGE #datadir = /data/mysql/datainnodb_data_file_path = ibdata1:1024M:autoextendinnodb_data_home_dir = /data/mysql/datainnodb_log_group_home_dir = /data/mysql/data# MyISAM #key-buffer-size = 16M# SAFETY #back_log = 512max-allowed-packet = 16Mmax-connect-errors = 1000wait_timeout = 100interactive_timeout = 100skip-name-resolveskip-external-lockingevent_scheduler = OFFexplicit-defaults-for-timestamp =1sysdate-is-now = 1innodb = FORCE# BINARY LOGGING ##log-bin = /data/mysql/log/mysql-binlog-bin = /data/mysql/log/mysql-binbinlog-format = mixedexpire-logs-days = 7sync-binlog = 100binlog_cache_size = 8M# REPLICATION #server-id = 4relay-log = /data/mysql/log/relay-binslave-net-timeout = 60# CACHES AND LIMITS #tmp-table-size = 512Mmax-heap-table-size = 64Mquery-cache-type = 0query-cache-size = 0max-connections = 500thread-cache-size = 2000open-files-limit = 65535table-definition-cache = 4096table-open-cache = 20480transaction_isolation = READ-COMMITTEDskip-external-locking = 1# INNODB #innodb-flush-method = O_DIRECTinnodb-log-files-in-group = 2innodb-log-file-size = 256Minnodb-buffer-pool-size = 4Ginnodb_read_io_threads = 4innodb_write_io_threads = 4innodb_io_capacity = 500innodb_strict_mode = 1innodb_file_format = Barracudainnodb_file_format_max = Barracudainnodb_purge_threads = 1innodb_use_sys_mallocinnodb_additional_mem_pool_size = 8Minnodb-flush-log-at-trx-commit = 2innodb-file-per-table = 1innodb_support_xa = 0# BUFFER #read_buffer_size = 2Mjoin_buffer_size = 2Msort_buffer_size = 2M# LOGGING #log-error = /data/mysql/log/mysql-error.loglog-queries-not-using-indexes = 0slow-query-log = 1long_query_time = 2slow-query-log-file = /data/mysql/log/mysql-slow.log
=======================
初始化
/usr/local/mysql-5.6.27/scripts/mysql_install_db --basedir=/usr/local/mysql-5.6.27 --datadir=/data/mysql/data --defaults-file=/etc/my.cnf
===================
创建快捷启动级开机服务启动
vi /lib/systemd/system/mysql.service
[Unit]Description=The MYSQL Process ManagerAfter=network.target[Service]Type=forkingExecStart=/usr/local/mysql-5.6.27/support-files/mysql.server startExecReload=/usr/local/mysql-5.6.27/support-files/mysql.server restartExecStop=/usr/local/mysql-5.6.27/support-files/mysql.server stopPrivateTmp=true[Install]WantedBy=multi-user.target
chmod +x /lib/systemd/system/mysql.service
systemctl enable mysql.service
systemctl start mysql.service
=======================
启动mysql创建本地管理帐号及删除无密码帐号
/usr/local/mysql-5.6.27/bin/mysqladmin -u root password 'orange#123'
/usr/local/mysql-5.6.27/bin/mysql -uroot -p'orange#123' -e "delete from mysql.user where password='';"
/usr/local/mysql-5.6.27/bin/mysql -uroot -p'orange#123' -e "flush privileges;"
#添加环境变量
vi /etc/profile
#add path for mysql
MYSQL_PATH=/usr/local/mysql-5.6.27/bin/
PATH=$PATH:$MYSQL_PATH
export PATH MYSQL_PATH
创建用户
/usr/local/mysql-5.6.27/bin/mysql -uroot -p
create user 'orange'@'%' identified by 'Hu#jgh%GVhb@5dGf35';
grant all privileges on *.* to 'orange'@'%';
flush privileges;
//备份语句
/usr/local/mysql-5.6.27/bin/mysqldump -udumper -p‘back#123654’ -hlocalhost -P4568 orange > orange_`date +%F_%T`.sql
//还原语句
mysql -uroot -p123456 orange</data/mysql_backup/orange_2017-04-07_11\:15\:00.sql
主从
从库账号密码
/usr/local/mysql-5.6.27/bin/mysqladmin -u root password 'sd#dfJGR8674#@%fgjk'
创建从者账号
CREATE USER 'slaver'@'%' IDENTIFIED BY 'sd#dfJGR8674#@%fgjk';
GRANT REPLICATION SLAVE ON *.* TO 'slaver'@'%';
CHANGE MASTER TO MASTER_HOST='120.77.254.17',MASTER_USER='slaver',MASTER_PASSWORD='sd#dfJGR8674#@%fgjk',MASTER_LOG_FILE='mysql-bin.000009',MASTER_LOG_POS=120;