MySQL的安装方式一般分三种:基于RPM包安装,基于二进制包安装,基于源代码安装。不同的安装方式,
所有的知识面不一样。其实基于RPM包安装方便快捷,目录结构固定。因此,对于一般使用来说已足够。
1.安装RPM包
[
root@localhost PerconaServerRPM]# rpm -ivh Percona-Server-shared-56-5.6.28-rel76.1.el6.x86_64.rpm
[
root@localhost PerconaServerRPM]# rpm -ivh Percona-Server-client-56-5.6.28-rel76.1.el6.x86_64.rpm
[
root@localhost
PerconaServerRPM]# rpm -ivh Percona-Server-server-56-5.6.28-rel76.1.el6.x86_64.rpm
7.编辑配置my.cnf文件
Note:***************************************如遇下列报错场景******************************************
2.安装路径布局
Directory | Contents of Directory |
---|---|
/usr/bin | Client programs and scripts |
/usr/sbin | The mysqld server |
/var/lib/mysql | Log files, databases |
/usr/share/info | MySQL manual in Info format |
/usr/share/man | Unix manual pages |
/usr/include/mysql | Include (header) files |
/usr/lib/mysql | Libraries |
/usr/share/mysql | Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench | Benchmarks |
- 数据库目录 /var/lib/mysql/
- 配置文件 /usr/share/mysql (mysql.server命令及配置文件)
- 相关命令 /usr/bin (mysql,mysqladmin mysqldump等命令)
- 启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录)
3.创建数据MySQL的数据目录
#cd /arp
#mkdir data
4.迁移数据库的数据目录至/data目录中,输入如下命令
#
mv /var/lib/mysql/ /arp/data/
如新建,可删除上述数据目录
#rm -rf /arp/data/*
5.拷贝完后还需要修改/etc/rc.d/init.d/mysql的datadir目录值,我修改如下:
----------------修改内容----------------
basedir=
datadir=/arp/data/3306
# Set some defaults
mysqld_pid_file_path=/arp/data/3306/mysql.pid
----------------------------------------------
6.建立所需的数据目录
#cd /arp/data/
#mkdir -p /arp/data/{3306/{data,tmp,binlog,innodb_ts,innodb_log},backup,scripts}
#chown -R mysql:mysql 3306
#su - mysql
#vim /etc/my.cnf
保存my.cnf文件。
[client]
port = 3306
socket = /arp/data/3306/mysql.sock
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /arp/data/3306/mysql.sock
pid-file = /arp/data/3306/mysql.pid
datadir = /arp/data/3306/data
tmpdir = /arp/data/3306/tmp
explicit_defaults_for_timestamp
server-id = 1143306
lower_case_table_names = 1
character-set-server = utf8
federated
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,oracle
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,oracle
skip-name-resolve
max_connect_errors = 100000
interactive_timeout = 86400
wait_timeout = 86400
sync_binlog=0
#back_log=100
default-storage-engine = InnoDB
log_slave_updates = 1
#*********** Logs related settings ***********
log-bin = /arp/data/3306/binlog/mysql-bin
binlog_format= mixed
binlog_cache_size=32m
max_binlog_cache_size=64m
max_binlog_size=512m
long_query_time = 3
log_output = FILE
log-error = /arp/data/3306/mysql-error.log
slow_query_log = 1
slow_query_log_file = /arp/data/3306/slow_statement.log
#log_queries_not_using_indexes
general_log = 0
general_log_file = /arp/data/3306/general_statement.log
expire-logs-days = 14
relay-log = /arp/data/3306/binlog/relay-bin
relay-log-index = /arp/data/3306/binlog/relay-bin.index
#****** MySQL Replication 5.6 New Feature*********
master-info-repository=TABLE
relay-log-info-repository=TABLE
relay-log-recovery
#*********** INNODB Specific options ***********
innodb_buffer_pool_size = 2048M
#transaction-isolation=REPEATABLE-READ
#innodb_buffer_pool_instances = 8
innodb_data_home_dir = /arp/data/3306/innodb_ts
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_thread_concurrency = 8
innodb_log_buffer_size = 256M
innodb_log_file_size = 2G
innodb_log_files_in_group = 3
innodb_log_group_home_dir = /arp/data/3306/innodb_log
innodb_max_dirty_pages_pct = 70
#innodb_flush_method=O_DIRECT
#*********** percona_server_command_parameters***********
innodb_lru_scan_depth=4000
innodb_flush_neighbors=0
innodb_io_capacity=25000
innodb_io_capacity_max=50000
innodb_flush_log_at_trx_commit=1
innodb_buffer_pool_instances=15
innodb_file_format=Barracuda
innodb_checksum_algorithm=crc32
innodb_file_per_table=true
innodb_doublewrite=1
innodb_flush_method=O_DIRECT_NO_FSYNC
innodb_purge_threads=4
table_open_cache=15000
open_files_limit=15000
max_connections=15000
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_change_buffering=all
loose-innodb_sync_array_size=16
query_cache_type=OFF
thread_cache_size=1000
back_log=2000
connect_timeout=15
loose-metadata_locks_hash_instances=256
max_prepared_stmt_count=1048560
loose-performance_schema=0
# --- below is Percona Server Specific ---
innodb_sched_priority_cleaner=39
innodb_log_block_size=4096
innodb_adaptive_hash_index_partitions=65
[mysql]
no-auto-rehash
default-character-set=gbk
prompt = (\u@\h) [\d]>\_
保存my.cnf文件。
8.初始化MySQL数据库
#mysql_install_db --user=mysql --datadir=/arp/data/3306/data
#mysql_install_db --user=mysql --datadir=/arp/data/3306/data
9.启动MySQL数据库(两种方式)
#service mysql start
#mysqld_safe --defaults-file=/etc/my.cnf &
10.关闭MySQL数据库
#service mysql stop
#
mysqladmin -u${MYSQL_USER} -p${MYSQL_PASS} shutdown
Note:***************************************如遇下列报错场景******************************************
[
root@localhost 3306]# service mysql start
Starting MySQL (Percona Server)...The server quit without u[FAILED]PID file (/arp/data/3306/tmp/mysql.pid).
解决方式:
*关闭selinux
#setenforce 0
#
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config