1.MysSQL历史版本下载:https://downloads.mysql.com/archives/community/
可以下载单个rpm包,也可以下载全部.tar包。建议下载全部tar包。
例: RPM Bundle
(MySQL-5.6.34-1.el6.x86_64.rpm-bundle.tar)
2.MySQL部署
查询系统系统自带的MySQL包:
rpm -qa|grep mysql
rpm -qa|grep mariadb
删除自带的mysql ,rpm -e 包名 例:
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
安装mysql
CentOS系统版本下载
5.7:
wget download.op.uzoo.cn/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
5.6:
wget download.op.uzoo.cn/MySQL-5.6.34-1.el7.x86_64.rpm-bundle.tar
解压
5.7:
tar xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
tar zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.22
cd /usr/local && ln -s mysql-5.7.22 mysql
echo "#mysql
export MYSQL_HOME=/usr/local/mysql/
export PATH==${PATH}:${MYSQL_HOME}/bin" >>/etc/profile
source /etc/profile
5.6:
tar xvf MySQL-5.6.34-1.el7.x86_64.rpm-bundle.tar
5.6安装顺序
rpm -ivh MySQL-devel-5.6.34-1.el7.x86_64.rpm
rpm -ivh MySQL-embedded-5.6.34-1.el7.x86_64.rpm
rpm -ivh MySQL-shared-5.6.34-1.el7.x86_64.rpm
rpm -ivh MySQL-server-5.6.34-1.el7.x86_64.rpm
rpm -ivh MySQL-shared-compat-5.6.34-1.el7.x86_64.rpm
rpm -ivh MySQL-client-5.6.34-1.el7.x86_64.rpm
rpm -ivh MySQL-test-5.6.34-1.el7.x86_64.rpm
测试是否新安装的版本
mysql -V
运行实例
A.目录:/data/mysql_3306/
/3306_my.cnf
/3306.mysql
/binlog
/data
/log
执行:
mkdir -p /data/mysql_3306/{data,binlog,log}
chown mysql.mysql /data/mysql_3318 -R
B.初始化实例
MySQL5.6:
/usr/bin/mysql_install_db --defaults-file=/data/mysql_3318/3318_my.cnf
MySQL5.7:
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mnt/mysql_3308/data/
C.启动实例:
/usr/bin/mysqld_safe --defaults-file=/data/mysql_3318/3318_my.cnf首次运行
配置文件
[mysql]
CLIENT
port = 3306
socket = /mnt/mysql_3306/mnt/mysql.sock
[mysqld]
GENERAL
port = 3306
user = mysql
default-storage-engine = InnoDB
socket = /mnt/mysql_3306/data/mysql.sock
pid-file = /mnt/mysql_3306/data/mysql.pid
character-set-server = utf8mb4
wait_timeout = 300
sql_mode = "NO_ENGINE_SUBSTITUTION"
MyISAM
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
myisam-recover-options = FORCE,BACKUP
SAFETY
max-allowed-packet = 64M
max-connect-errors = 1000000
default_password_lifetime = 0
DATA STORAGE
datadir = /mnt/mysql_3306/data/
BINARY LOGGING
binlog_format = ROW
log-bin = /mnt/mysql_3306/binlog/mysql-bin
max_binlog_size = 512M
expire-logs-days = 7
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=false
master-info-repository=TABLE
relay-log-info-repository=TABLE
replicate-ignore-db = mysql
REPLICATION
relay-log = /mnt/mysql_3306/binlog/relay-bin
slave-net-timeout = 60
server-id = 1341293306
CACHES AND LIMITS
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max_connections = 3000
thread-cache-size = 32
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
INNODB
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 256M
innodb-flush-log-at-trx-commit = 2
innodb-file-per-table = 1
innodb-buffer-pool-size = 3G
sync_binlog = 1000
slave-skip-errors=all
LOGGING
log-error = /mnt/mysql_3306/log/mysql-error.log
slow-query-log = 1
long_query_time = 3
slow-query-log-file = /mnt/mysql_3306/log/mysql-slow.log
首次运行MySQL5.7实例
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mnt/mysql_3306/data/
mysqld_safe --defaults-file=/mnt/mysql_3306/3306_my.cnf &
mysql -uroot -h127.0.0.1 -P3306 -p
设置重置root密码
set password=password('12345678');
变更临时密码
use mysql;
delete from user where user='';
delete from user where user='root';
GRANT SELECT, SHUTDOWN, PROCESS, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON . TO 'manager'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
GRANT REPLICATION SLAVE ON . TO 'repl'@'%' IDENTIFIED BY '123456';
CREATE USER 'haproxy'@'%';
GRANT Usage ON . TO haproxy@'%';
GRANT SUPER ON . TO 'monitor'@'%' IDENTIFIED BY '123456';
COMMIT;
FLUSH PRIVILEGES;
删除默认空用户:
mysql -uroot -h127.0.0.1 -e "use mysql;delete from user where user='';"
mysql -uroot -h127.0.0.1 -e "use mysql;delete from user where user='root';"
查看已有用户权限:
show grants for manager;
#新建管理用户manager:
GRANT SELECT, SHUTDOWN, PROCESS, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON . TO 'manager'@'%' IDENTIFIED BY '123456';
#变更root账户密码:
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
脚本启动:/data/mysql_3306/3306.mysqld start
#!/bin/bash
port=3318
mysql_user="manager"
mysql_pwd="123456"
CmdPath="/usr/bin"
mysql_sock="/data/mysql_${port}/data/mysql.sock"
startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL…\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/mysql_${port}/${port}_my.cnf 2>&1 > /dev/null &
else
printf "MySQL is running…\n"
exit
fi
}
stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped…\n"
exit
else
printf "Stoping MySQL…\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
fi
}
restart function
function_restart_mysql()
{
printf "Restarting MySQL…\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac