mysql5.7初始化过程

1.上传至目录或在服务器端下载mysql
cd /opt/sudytech

wget http://101.96.10.71/dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz


2.解压mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
tar -xzvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz


3.更改mysql目录名称
mv mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz mysql


4.将如下mysql配置文件保存至/etc/my.cnf


# For advice on how to change settings  please see
# *** DO NOT EDIT THIS FILE. It's a  template which will be copied to the
# *** default location during install,  and will be replaced if you
# *** upgrade to a newer version of  MySQL.
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character-set-server = utf8
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /opt/sudytech/mysql/
datadir = /opt/sudytech/mysql/data
log-error =  /opt/sudytech/mysql/data/log-error.log
pid-file =  /opt/sudytech/mysql/data/mysql.pid
innodb_data_home_dir =  /opt/sudytech/mysql/data
slow-query-log-file=/opt/sudytech/mysql/data/slow.log
#log-bin  =/opt/sudytech/mysql/data/binlog
relay-log-index =  /opt/sudytech/mysql/data/relaylog
relay-log-info-file =  /opt/sudytech/mysql/data/relaylog
relay-log =  /opt/sudytech/mysql/data/relaylog
open_files_limit = 10240
table_open_cache = 512
back_log = 300
max_connections = 3000
max_connect_errors = 10000
#skip-external-locking
max_allowed_packet = 64M
thread_cache_size = 300
thread_concurrency = 16
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 512M
max_heap_table_size = 512M
key_buffer_size = 512M
sort_buffer_size = 6M
join_buffer_size = 6M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 15G
myisam_repair_threads = 1
myisam_recover = 64K
interactive_timeout = 28800
wait_timeout = 28800
innodb_data_file_path =  ibdata1:1024M;ibdata2:2048M:autoextend
innodb_additional_mem_pool_size = 200M
innodb_buffer_pool_size = 4G
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
slow_query_log = 1
long_query_time = 3
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db =  information_schema
#binlog_cache_size = 4M
#binlog_format = MIXED
#max_binlog_cache_size = 64M
#max_binlog_size = 1G
#expire_logs_days = 30
#slave-skip-errors =  1032,1062,1026,1114,1146,1048,1396
server-id = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet = 64M
注:
thread_concurrency、innodb_thread_concurrency 
对应服务器cpu线程数,可以调小,但不可过大
文中配置文件以8G内存为标准配置,实际内存等于或低于8G,请降低部分缓存参数
thread_concurrency
myisam_recover
innodb_file_io_threads
等设置涉及虚拟化和多线程,取决于cpu和系统是否支持,参照errorlog,如有报错,删除对应参数,此文档my.cnf为最大化配置项




5.建立非登录用户mysql
adduser -s /sbin/nologin mysql
makedir /opt/sudytech/mysql/data
chown mysql /opt/sudytech/mysql/data

6.初始化mysql
cd /opt/sudytech/mysql
./bin/mysqld --initialize --user=mysql


7.查看mysql日志(/opt/sudytech/mysql/data/log-error.log),查看初始化密码
localhost: xxxxxxxxx


8.使用初始密码登录,grant赋予本地权限
/opt/sudytech/mysql/bin/mysqladmin -u root -p'xxxxx(步骤7密码)' password 'xxxxx(新密码)'


9.使用secureinstall进行安全模块安装
/opt/sudytech/mysql/bin/mysql_secure_installation

根据提示进行设置:
a.是否部署密码复杂度检查模块(复杂度级别)
b.是否清除非管理员用户
c.是否允许管理员远程登录mysql
d.是否删除公共test库