CentOS7 安装MySQL5.6
1. 安装依赖包
yum -y install libaio autoconf numactl.x86_64
2. 创建一个mysql用户和组
groupadd -g 1055 mysql
useradd -r -u 1055 -g mysql -s /bin/false mysql
3. 创建数据目录和log目录
mkdir -p /data/.storage/mysql/50200
mkdir -p /data/log/sys/mysql
chown -R mysql.mysql /data/log/sys/mysql
4. 下载、解压mysql
cd /usr/local
wget -c https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz
ln -s mysql-5.6.45-linux-glibc2.12-x86_64 mysql
cd mysql
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/.storage/mysql/50200/
export PATH=$PATH:/usr/local/mysql/bin
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
5. systemctl启动配置
# vim /etc/systemd/system/mysql50200.service
[Unit]
Description=mysql50200
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network-online.target rsyslog.target
[Service]
User=mysql
Group=mysql
PIDFile=/data/.storage/mysql/50200/pid.pid
ExecStart=/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/etc/50200.mysql.conf --user=mysql
PrivateTmp=true
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
6. 50200.mysql.conf配置文件
[client]
port = 50200
server-id = 50200
socket = /data/.storage/mysql/50200/sock.sock
[mysqld]
port = 50200
datadir = /data/.storage/mysql/50200
socket = /data/.storage/mysql/50200/sock.sock
pid-file = /data/.storage/mysql/50200/pid.pid
server-id = 999991
log-bin = 50200-bin
binlog-format = mixed
skip-name-resolve
back_log = 3000
#InnoDB设置
innodb_use_native_aio = 0
innodb_buffer_pool_size = 512M
innodb_thread_concurrency = 16
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 48M
innodb_file_per_table = 1
#innodb_force_recovery = 1
skip-external-locking
explicit_defaults_for_timestamp = 1
local-infile = 0
max_connections = 3000
max_connect_errors = 100
key_buffer_size = 256M
query-cache-type = 1
query_cache_size = 64M
max_allowed_packet = 8M
thread_stack = 256K
thread_cache_size = 64
query_cache_limit = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
read_buffer_size = 8M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 16M
tmp_table_size = 256M
max_heap_table_size = 64M
connect_timeout = 60
#fix mysql gone away
wait_timeout = 10
interactive-timeout = 600
# log
general-log = 0
slow_query_log = 1
long_query_time = 2
log-queries-not-using-indexes
general-log-file = /data/log/sys/mysql/50200_gen.log
slow-query-log-file = /data/log/sys/mysql/50200_slow.log
log-error = /data/log/sys/mysql/50200_error.log
expire_logs_days = 4
[mysqldump]
max_allowed_packet = 100M
[mysql]
no-auto-rehash
default_character_set = utf8
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 256M
read_buffer_size = 8M
read_rnd_buffer_size = 32M
write_buffer_size = 256M
[mysqlhotcopy]
interactive-timeout
7. 启动mysql
systemctl daemon-reload
systemctl start mysql50200
systemctl stop mysql50200
systemctl start mysql50200
8. 报错处理
(1) 初始化报错
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/.storage/mysql/50200/
FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper
解决方法 :安装autoconf库
命令:yum -y install autoconf
# scripts/mysql_install_db --user=mysql
Use of uninitialized value in chown at scripts/mysql_install_db line 705.
Use of uninitialized value in chown at scripts/mysql_install_db line 705.
Use of uninitialized value in chown at scripts/mysql_install_db line 705.
Use of uninitialized value in chown at scripts/mysql_install_db line 705.
Use of uninitialized value in chown at scripts/mysql_install_db line 705.
Use of uninitialized value in chown at scripts/mysql_install_db line 705.
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
解决方法:创建用户并安装libnuma.so.1
命令:
yum -y install libaio numactl.x86_64
groupadd -g 1055 mysql
useradd -r -u 1055 -g mysql -s /bin/false mysql
Installing MySQL system tables...2019-08-13 11:25:45 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details)
初始化时不影响安装:
解决方法:
在my.cnf中加入
[mysqld]
explicit_defaults_for_timestamp=true
参考链接:
下载网址: https://dev.mysql.com/downloads/mysql/
安装文档: https://dev.mysql.com/doc/refman/5.6/en/binary-installation.html