by 007

MySQL5.7安装初始化

2020.11.06
MySQL5.7安装初始化(二进制安装包)

1.add user

useradd -M -s /sbin/nologin mysql

2.init base

tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /data/mysql

mkdir /data/mysql/data
mv /etc/my.cnf /tmp
touch /data/mysql/error.log

cp /data/mysql/support-files/mysql.server /data/mysql/

/data/mysql/support-files/mysql.server
...
basedir=/data/mysql
datadir=/data/mysql/data
...

3.add config file

cat <<EOF>> /data/mysql/my.cnf
[mysqld]
user 	= mysql
basedir = /data/mysql
datadir = /data/mysql/data
port 	= 3306
socket	= /tmp/mysql.sock
log-error = /data/mysql/error.log
pid-file  = /data/mysql/mysql.pid

default-time_zone = '+8:00'

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

character_set_server    = utf8
skip_name_resolve       = 1
back_log                = 100
max_allowed_packet      = 16M
max_connections         = 5000

log_timestamps = SYSTEM

#query_cache_size  = 512
#query_cache_limit = 2M
log_bin_trust_function_creators = 1

skip_external_locking   = 1
#key_buffer_size = 128M
read_buffer_size        = 2M
read_rnd_buffer_size    = 4M
sort_buffer_size        = 32M
join_buffer_size        = 32M
net_buffer_length       = 8K
#table_cache             = 4096

table_open_cache        = 2048
tmp_table_size          = 512M
max_heap_table_size     = 512M

thread_cache_size       = 64
group_concat_max_len    = 2048

default_storage_engine          = InnoDB
innodb_data_file_path           = ibdata1:10M:autoextend
innodb_flush_log_at_trx_commit  = 1
innodb_log_buffer_size          = 16M
innodb_log_file_size            = 256M
innodb_log_files_in_group       = 3
innodb_buffer_pool_size         = 2G
innodb_thread_concurrency       = 16
innodb_file_per_table           = 1
innodb_open_files               = 1024

server_id			= 200
log_bin                         = mysql-bin
binlog_format                   = mixed
binlog_cache_size               = 2M
slow_query_log
slow_query_log_file             = slow_query.log
long_query_time                 = 1
performance_schema      = 1

[mysqldump]
quick
max_allowed_packet = 16M
EOF

4.init server

chown -R mysql:mysql /data/mysql

/data/mysql/bin/mysqld --defaults-file=/data/mysql/my.cnf --initialize --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data

password in /data/mysql/error.log

5.start mysql

/data/mysql/mysql.server start

6.root user

/data/mysql/bin/mysql -uroot -p

mysql> alter user user() identified by 'passwd';