5.7
cd /usr/local/src/
wget "http://distfiles.macports.org/cmake/cmake-3.10.2.tar.gz"
tar -zxvf cmake-3.10.2.tar.gz
cd cmake-3.10.2
./bootstrap
gmake && gmake install
cd ..
wget "http://mirror.neu.edu.cn/mysql/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz"
tar -zxvf mysql-5.7.10.tar.gz
cd mysql-5.7.10
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.10
-DMYSQL_DATADIR=/data/mysql/
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii
-DENABLED_LOCAL_INFILE=ON
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
-DWITH_ZLIB=bundled
-DWITH_EMBEDDED_SERVER=1
-DWITH_DEBUG=0
-DWITH_BOOST=/usr/local/boost
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 = 4568
socket = /data/mysql/log/mysql.sock
[mysqld]
user = mysql
port = 4568
character-set-server = utf8
default-storage-engine = InnoDB
socket = /data/mysql/log/mysql.sock
pid-file = /data/mysql/log/mysql.pid
# DATA STORAGE #
datadir = /data/mysql/data
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_data_home_dir = /data/mysql/data
innodb_log_group_home_dir = /data/mysql/data
# MyISAM #
key-buffer-size = 16M
# SAFETY #
back_log = 512
max-allowed-packet = 16M
max-connect-errors = 1000
wait_timeout = 100
interactive_timeout = 100
skip-name-resolve
skip-external-locking
event_scheduler = OFF
explicit-defaults-for-timestamp =1
sysdate-is-now = 1
innodb = FORCE
# BINARY LOGGING #
#log-bin = /data/mysql/log/mysql-bin
log-bin = /data/mysql/log/mysql-bin
binlog-format = mixed
expire-logs-days = 7
sync-binlog = 100
binlog_cache_size = 8M
# REPLICATION #
server-id = 4
relay-log = /data/mysql/log/relay-bin
slave-net-timeout = 60
# CACHES AND LIMITS #
tmp-table-size = 512M
max-heap-table-size = 64M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 2000
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 20480
transaction_isolation = READ-COMMITTED
skip-external-locking = 1
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 256M
innodb-buffer-pool-size = 4G
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_io_capacity = 500
innodb_strict_mode = 1
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_purge_threads = 1
innodb_use_sys_malloc
innodb_additional_mem_pool_size = 8M
innodb-flush-log-at-trx-commit = 2
innodb-file-per-table = 1
innodb_support_xa = 0
# BUFFER #
read_buffer_size = 2M
join_buffer_size = 2M
sort_buffer_size = 2M
# LOGGING #
log-error = /data/mysql/log/mysql-error.log
log-queries-not-using-indexes = 0
slow-query-log = 1
long_query_time = 2
slow-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 Manager
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql-5.6.27/support-files/mysql.server start
ExecReload=/usr/local/mysql-5.6.27/support-files/mysql.server restart
ExecStop=/usr/local/mysql-5.6.27/support-files/mysql.server stop
PrivateTmp=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;
以上是 5.7 的全部内容, 来源链接: utcz.com/z/513466.html