MySQL 安装部署
目录
环境:CentOS MySQL 8.0.22
创建用户 创建环境变量 授权数据目录 初始化/启动/关闭 检查启动状态 待续
依赖包
yum -y install numactl
创建用户
id mysql &>/dev/null || useradd mysql -s /sbin/nologin
创环境变量
程序目录
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 10:56:58 /Server/program-files ]
# ll
total 0
lrwxrwxrwx. 1 root root 14 Jan 1 22:55 mysql -> ./mysql-8.0.22
drwxr-xr-x. 9 root root 129 Jan 1 18:12 mysql-8.0.22
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 10:57:58 /Server/program-files ]
# ls mysql-8.0.22
bin docs include lib LICENSE man README share support-files
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:09:54 /usr/local ]
# ln -s /Server/program-files/mysql mysql
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:10:17 /usr/local ]
# ll mysql
lrwxrwxrwx 1 root root 27 Jan 2 11:10 mysql -> /Server/program-files/mysql
环境变量
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:07:14 /Server/program-files ]
# tail -n 20 /etc/profile
# common var
export ROOT_PATH='/Server/program-files'
export BIN_DIR='bin'
# MySQL var
export MYSQL_HOME=${ROOT_PATH}/mysql/${BIN_DIR}
export MYSQL_SHELL=${ROOT_PATH}/mysql_shell/${BIN_DIR}
export MYSQL_ROUTER=${ROOT_PATH}/mysql_router/${BIN_DIR}
export PATH=${MYSQL_HOME}:${MYSQL_SHELL}:${MYSQL_ROUTER}:$PATH
export MYSQL_PS1='\u@\h@\p[\d] \r:\m:\s >'
授权数据目录
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:21:27 /Server/datas/mysql-8.0.22-3306 ] # chown -R mysql.mysql /Server/datas/mysql-8.0.22-3306 [ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:22:03 /Server/datas/mysql-8.0.22-3306 ] # tree -pu /Server/datas/mysql-8.0.22-3306 /Server/datas/mysql-8.0.22-3306 ├── [drwxr-xr-x mysql ] conf ├── [drwxr-xr-x mysql ] data ├── [drwxr-xr-x mysql ] log-bin ├── [drwxr-xr-x mysql ] log-relay └── [drwxr-xr-x mysql ] tmp
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:50:05 /Server ]
# chmod 777 /Server/{logs,runnings}
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:50:43 /Server ]
# chmod o+t /Server/{logs,runnings}
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 11:50:52 /Server ]
# ls -ld /Server/{logs,runnings}
drwxrwxrwx. 2 root root 6 Dec 18 22:11 /Server/logs
drwxrwxrwx. 2 root root 6 Dec 18 22:11 /Server/runnings
配置文件
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 15:13:43 /Server/datas/mysql-8.0.22-3306 ]
# cat conf/my.cnf
[mysqld]
# base
user=mysql
server-id=1
basedir=/Server/program-files/mysql
datadir=/Server/datas/mysql-8.0.22-3306/data
tmpdir=/Server/datas/mysql-8.0.22-3306/tmp
# port
bind-address=192.168.6.100
port=3306
report_host=192.168.6.100
report_port=3306
socket=/dev/shm/mysql_8.0.22_3306.sock
mysqlx_port=33060
mysqlx_socket=/Server/runnings/mysql_8.0.22_3306_x.sock
pid_file=/Server/runnings/mysql_8.0.22_3306.pid
admin_port=33062
admin_address='127.0.0.1'
create_admin_listener_thread=on #8.0.20:OFF
# character
character-set-server=utf8mb4
# connect
max_connections=500 #8.0.20:151
max_user_connections=400 #8.0.20:0
max_connect_errors=3000 #8.0.20:100
#mysqlx_max_connections=300
max_allowed_packet=64MB #8.0.20:67108864
session_track_gtids=OWN_GTID
skip_name_resolve=on
# session
sort_buffer_size=2M #8.0.20:262144
join_buffer_size=4M #8.0.20:262144
thread_cache_size=64 #8.0.20:9
thread_stack=512K #8.0.20:286720
tmp_table_size=32M #8.0.20:16777216(16M)
read_buffer_size=2M #8.0.20:131072(128K)
read_rnd_buffer_size=4M #8.0.20:262144
bulk_insert_buffer_size=8M #8.0.20:262144
# timeout
interactive_timeout=300 #8.0.20:28800
wait_timeout=300 #8.0.20:28800
innodb_rollback_on_timeout=on #8.0.20:OFF
slave_net_timeout=300 #8.0.20:60
rpl_stop_slave_timeout=1800 #8.0.20:31536000
lock_wait_timeout=300 #8.0.20:31536000
# log
# binlog
log-bin=/Server/datas/mysql-8.0.22-3306/log-bin/tb_b4_b100_3306 # 命名规则: tb:淘宝,b4:北京4区,b:binlog,100:ip地址最后一段
binlog_format=row
binlog_rows_query_log_events=on # 8.0.20:OFF
log_slave_updates = on
binlog_checksum=none
expire_logs_days=7
gtid_mode=on
enforce_gtid_consistency=on
binlog_cache_size=1M # 8.0.20:32KB
#max_binlog_size=512M # 8.0.20:1G
sync_binlog=0
binlog_group_commit_sync_delay=100
binlog_group_commit_sync_no_delay_count=10
binlog_order_commits=off
# slow log
slow_query_log=on
long_query_time=0.5
slow_query_log_file=/Server/logs/mysql_8.0.22_3306_slow.log
log_queries_not_using_indexes=on
# error log
log_error=/Server/logs/mysql_8.0.22_3306_error.log
#log_error_verbosity=3
# innoDB
innodb_buffer_pool_size=2G #8.0.20:134217728
innodb_buffer_pool_instances=1 #8.0.20:1
innodb_data_file_path=ibddata1:512M:autoextend #8.0.20:ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit=0
innodb_flush_method=O_DIRECT_NO_FSYNC
innodb_log_buffer_size=16M #8.0.20:16777216
innodb_log_file_size=256M #8.0.20:50331648
innodb_log_files_in_group=3 #8.0.20:2
innodb_max_dirty_pages_pct=90 #8.0.20:90
innodb_file_per_table=1 #8.0.20:ON
#innodb_rollback_on_timeout=on #8.0.20:OFF
innodb_io_capacity=2000 #8.0.20:200
innodb_io_capacity_max=4000 #8.0.20:2000
innodb_read_io_threads =2 #8.0.20:4
innodb_write_io_threads=2 #8.0.20:4
innodb_print_all_deadlocks=1 #8.0.20:OFF
# thread
thread_cache_size=64 #8.0.20:64
# relay log & apply
relay_log=/Server/datas/mysql-8.0.22-3306/log-relay/tb_b4_r100_3306 # 命名规则与binlog一致
relay_log_info_file=relay-bin.index
relay_log_info_repository=table
relay_log_purge=on
sync_relay_log=10000
sync_relay_log_info=10000
relay_log_recovery=on
slave_preserve_commit_order=on
slave_parallel_type=LOGICAL_CLOCK
slave_parallel_workers=2
transaction_write_set_extraction='XXHASH64'
binlog_transaction_dependency_tracking='writeset' # defaults:COMMIT_ORDER
binlog_transaction_dependency_history_size=25000 # default:25000
初始化 / 启动 / 关闭数据库
无密码初始化后(注意该方法适合 mysql 5.7 以上版本)
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 15:11:39 /Server/datas/mysql-8.0.22-3306 ]
# mysqld --defaults-file="/Server/datas/mysql-8.0.22-3306/conf/my.cnf" --initialize-insecure
注意 mysqld 与 mysqld_safe 的启动方式(建议使用mysqld启动方式,若使用 mysqld_safe 在MySQL被再次拉起时会有小概率对数据进行二次损坏)
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 15:12:30 /Server/datas/mysql-8.0.22-3306 ]
# mysqld --defaults-file="/Server/datas/mysql-8.0.22-3306/conf/my.cnf" &
[1] 3501
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 15:12:42 /Server/datas/mysql-8.0.22-3306 ]
# ps -ef | grep [m]ysql
mysql 3501 2519 14 15:12 pts/0 00:00:01 mysqld --defaults-file=/Server/datas/mysql-8.0.22-3306/conf/my.cnf
[ root@stock.data.news.100 pts/0 2021-01-02/31@6 15:17:57 /Server/logs ]
# mysql -S /dev/shm/mysql_8.0.22_3306.sock
root@localhost@mysql_8.0.22_3306.sock[(none)] 03:18:58 >select version();
+-----------+
| version() |
+-----------+
| 8.0.22 |
+-----------+
1 row in set (0.00 sec)
root@localhost@mysql_8.0.22_3306.sock[(none)] 03:19:43 >shutdown;
Query OK, 0 rows affected (0.01 sec)
root@localhost@mysql_8.0.22_3306.sock[(none)] 03:21:42 >quit
Bye
检查启动状态
[ root@stock.data.news.100 pts/1 2021-01-02/31@6 15:25:49 ~ ] # netstat -lntup | grep 3306 tcp 0 0 127.0.0.1:33062 0.0.0.0:* LISTEN 3651/mysqld tcp 0 0 192.168.6.100:3306 0.0.0.0:* LISTEN 3651/mysqld tcp6 0 0 :::33060 :::* LISTEN 3651/mysqld
[ root@stock.data.news.100 pts/1 2021-01-02/31@6 15:26:16 ~ ]
# mysqladmin -S /dev/shm/mysql_8.0.22_3306.sock ping
mysqld is alive
[ root@stock.data.news.100 pts/1 2021-01-02/31@6 15:26:27 ~ ]
# ps -ef | grep [m]ysql
mysql 3651 2519 1 15:24 pts/0 00:00:01 mysqld --defaults-file=/Server/datas/mysql-8.0.22-3306/conf/my.cnf
[ root@stock.data.news.100 pts/1 2021-01-02/31@6 15:26:36 ~ ]
# ls /dev/shm/mysql_8.0.22_3306.sock
/dev/shm/mysql_8.0.22_3306.sock
[ root@stock.data.news.100 pts/1 2021-01-02/31@6 15:27:37 ~ ]
# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 3651 mysql 37u IPv4 58754 0t0 TCP 192.168.6.100:mysql (LISTEN)
posted on 2021-01-02 11:04 3L·BoNuo·Lotus 阅读(59) 评论(0) 编辑 收藏 举报