mysql 安装、配置
一、解压安装包到指定路径 tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
二、重命名解压后的文件 mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql
创建mysql安装目录 mkdir -p /data/mysql/mysql3306 cd /data/mysql/mysql3306
mkdir data logs tmp
三、添加用户和组 groupadd mysql
useradd -r -g mysql -s /bin/false mysql -- -r参数表示mysql用户是系统用户,不可用于登录系统
四、修改目录属主属组 cd /usr/local chown -R mysql mysql/
chgrp -R mysql mysql/
五、创建配置文件 vim /data/mysql/mysql3306/my3306.cnf
#my.cnf [client] port = 3306
#socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysql] prompt='(product)\u@\h [\d]>'
#tee=/data/mysql/mysql3306/data/query.log
no-auto-rehash
default-character-set = utf8mb4
[mysqld]
#misc user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
port = 3306
#socket = /tmp/mysql.sock
event_scheduler = 0
#tmp tmpdir=/data/mysql/mysql3306/tmp
#不区分大小写 lower_case_table_names = 1
# performance schema performance_schema = OFF
#timeout interactive_timeout = 3600 wait_timeout = 3600
#character set character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
character-set-client-handshake = FALSE
init_connect='SET NAMES utf8mb4'
open_files_limit = 65535
max_connections = 2048
max_connect_errors = 100000
skip-name-resolve = 1
#logs log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
pid-file = mysql.pid
long_query_time = 0.2
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
explicit_defaults_for_timestamp=1
#binlog binlog_format = row
server-id = 2503306
log-bin = /data/mysql/mysql3306/logs/mysql-bin
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 2G
sync_binlog = 1 innodb_flush_log_at_trx_commit = 1 expire_logs_days = 7
#buffers &
cache table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
#innodb
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 4
innodb_data_file_path = ibdata1:10M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 64M
innodb_log_file_size = 200M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_status_file = 1
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
thread_stack=4M
[mysqld_safe]
malloc-lib=/usr/local/mysql/lib/jmalloc.so
nice=-19 open-files-limit=65535
----修改默认启动文件 cd /etc mv my.cnf my.cnf_bak
cd /data/mysql chown mysql.mysql mysql3306/ -R
六、初始化数据库 yum install libaio
---/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US ---指定配置文件初始化数据库 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize --user=mysql
cd /data/mysql/mysql3306/data vi error.log ---mysql root 初始化 密码:A temporary password is generated for root@localhost: *y1K7rMye6tl
七、启动mysql
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
---/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql3306/my3306.cnf --user=mysql &
八、修改root初始化密码
/usr/local/mysql/bin/mysql -uroot -p*y1K7rMye6tl
set password=password('123456');
show databases;
九、设置开机自动启动 cd /usr/local/mysql cp support-files/mysql.server /etc/init.d/mysql
配置启动文件
cp support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
chkconfig --add mysql chkconfig mysql on
mysql -uroot -p123456
十、关闭mysql /usr/local/mysql/bin/mysqladmin -uroot -p shutdown