概述
MySQL是一个关系型数据库管理系统由瑞典MySQL AB 公司开发,目前属于Oracle旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件。
1.前期规划
System | IPaddr | 主机名 | Software |
---|---|---|---|
CentOS-6.8-x86_64 | 192.168.10.10 | mysql-master | mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz |
2.安装前准备
2.1 配置主机名静态IPaddr
###修改主机名
[root@localhost ~]# hostname mysql-master
[root@localhost ~]# bash
[root@mysql-master ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mysql-master
###配置/etc/hosts
[root@mysql-master ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10 mysql-master
###配置静态IPaddr
[root@mysql-master ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.10.10
NETMASK=255.255.255.0
###重启网络服务生效
[root@mysql-master ~]# /etc/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
Bringing up interface eth1: Determining if ip address 192.168.10.10 is already in use for device eth1...
[ OK ]
2.2 配置aliyun yum源
[root@mysql-master yum.repos.d]# cd /etc/yum.repos.d/
[root@mysql-master yum.repos.d]# find . -type f -name "*.repo" | xargs -i mv {} {}.bak
[root@mysql-master yum.repos.d]# curl -so /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@mysql-master yum.repos.d]# ls
CentOS-Base.repo CentOS-Base.repo.bak
[root@mysql-master yum.repos.d]# yum makecache
2.3 下载MySQL二进制软件包
[root@mysql-master ~]# yum install -y wget
[root@mysql-master ~]# cd /tmp/
[root@mysql-master tmp]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
3.MySQL安装部署
3.1 配置MySQL用户与用户组
[root@mysql-master ~]# groupadd -g 1000 dba
[root@mysql-master ~]# useradd -u 2000 -g dba -G root -d /usr/local/mysql mysqladmin
3.2 初始化用户环境变量COPY
[root@mysql-master ~]# alias cp=cp
[root@mysql-master ~]# cp -apR /etc/skel/.bash_logout /usr/local/mysql/
[root@mysql-master ~]# cp -apR /etc/skel/.bash_profile /usr/local/mysql/
[root@mysql-master ~]# cp -apR /etc/skel/.bashrc /usr/local/mysql/
3.3 配置文件my.cnf与用户权限
##增加配置文件
vim /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
[mysqld]
user = mysqladmin
port = 3306
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size = 32M
max_allowed_packet = 16M
myisam_sort_buffer_size = 128M
tmp_table_size = 32M
table_open_cache = 512
thread_cache_size = 8
wait_timeout = 86400
interactive_timeout = 86400
max_connections = 600
# Try number of CPU's*2 for thread_concurrency
#thread_concurrency = 32
#isolation level and default engine
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED
server-id = 1
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/hostname.pid
#open performance schema
log-warnings
sysdate-is-now
binlog_format = MIXED
log_bin_trust_function_creators = 1
log-error = /usr/local/mysql/data/hostname.err
log-bin = /usr/local/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err
#for replication slave
#log-slave-updates
#sync_binlog = 1
#for innodb options
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ibdata1:200M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/arch
innodb_log_files_in_group = 2
innodb_log_file_size = 200M
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 50M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 100
#innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_locks_unsafe_for_binlog = 1
#innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads = 4
innodb-write-io-threads = 4
innodb-io-capacity = 200
#purge threads change default(0) to 1 for purge
innodb_purge_threads = 1
innodb_use_native_aio = on
#case-sensitive file names and separate tablespace
innodb_file_per_table = 1
lower_case_table_names = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
###修改用户权限
[root@mysql-master ~]# chown mysqladmin.dba /etc/my.cnf
[root@mysql-master ~]# chmod 640 /etc/my.cnf
3.4 初始化MySQL数据库
[root@mysql-master ~]# tar xf /tmp/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@mysql-master mysql]# cd /tmp/mysql-5.6.35-linux-glibc2.5-x86_64
[root@mysql-master mysql-5.6.35-linux-glibc2.5-x86_64]# mv * /usr/local/mysql/
[root@mysql-master ~]# chown mysqladmin.dba -R /usr/local/mysql/
[root@mysql-master ~]# su - mysqladmin
[mysqladmin@mysql-master ~]$ pwd
/usr/local/mysql
[mysqladmin@mysql-master ~]$ mkdir data
[mysqladmin@mysql-master ~]$ mkdir arch
###初始化MySQL
[mysqladmin@mysql-master ~]$ ./scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Installing MySQL system tables...2017-12-16 10:18:18 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-12-16 10:18:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-16 10:18:18 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-12-16 10:18:18 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.35-log) starting as process 3982 ...
OK
Filling help tables...2017-12-16 10:18:36 0 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-12-16 10:18:36 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-16 10:18:36 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-12-16 10:18:36 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.35-log) starting as process 4004 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h mysql-master password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.
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
3.5 设置MySQL全局环境变量
[root@mysql-master ~]# vim /etc/profile
MYSQL_BASE=/usr/local/mysql
export PATH=$MYSQL_BASE/bin/:$PATH
[root@mysql-master ~]# source /etc/profile
###验证环境变量是否生效
[root@mysql-master ~]# mysql
mysql mysqlcheck mysqld mysql_embedded mysql_secure_installation mysql_tzinfo_to_sql
mysqlaccess mysql_client_test mysqld-debug mysql_find_rows mysql_setpermission mysql_upgrade
mysqlaccess.conf mysql_client_test_embedded mysqld_multi mysql_fix_extensions mysqlshow mysql_waitpid
mysqladmin mysql_config mysqld_safe mysqlhotcopy mysqlslap mysql_zap
mysqlbinlog mysql_config_editor mysqldump mysqlimport mysqltest
mysqlbug mysql_convert_table_format mysqldumpslow mysql_plugin mysqltest_embedded
3.6 配置MySQL开机自启动
[root@mysql-master ~]# cp -apR /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@mysql-master ~]# chkconfig --del mysql
[root@mysql-master ~]# chkconfig --add mysql
[root@mysql-master ~]# chkconfig --level 345 mysql on
3.7 启动MySQL与服务验证
[mysqladmin@mysql-master ~]$ /etc/init.d/mysql start
Starting MySQL..... SUCCESS!
[mysqladmin@mysql-master ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
4.报错处理
4.1 需要创建arch目录
[root@mysql-master data]# cat hostname.err
2017-12-16 10:14:58 3968 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
2017-12-16 10:14:58 3968 [Warning] Buffered warning: Changed limits: max_connections: 214 (requested 600)
2017-12-16 10:14:58 3968 [Warning] Buffered warning: Changed limits: table_open_cache: 400 (requested 512)
/usr/local/mysql/bin/mysqld: File '/usr/local/mysql/arch/mysql-bin.index' not found (Errcode: 2 - No such file or directory)
2017-12-16 10:14:58 3968 [ERROR] Aborting
4.2 修改主机名未配置/etc/hosts
WARNING: The host 'mysql-master' could not be looked up with /usr/local/mysql/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
4.3 缺少libaio软件包
Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@mysql-master ~]# yum install -y libaio
4.4 basedir路径指向MySQL解压软件包根目录
FATAL ERROR: Could not find my-default.cnf
If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location.
如果您使用的是二进制版本,那么您必须位于提取的存档的顶层,或者通过指向该位置的basedir选项。