![04f18b9412be7b49622478175681d52c.png](https://i-blog.csdnimg.cn/blog_migrate/5d461e093b11d487f27098528f0527b5.jpeg)
环境准备:
腾讯云最小配置虚拟机
#cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
- 创建mysql用户组
#groupadd mysql
#useradd -g mysql -s /sbin/nologin -d /usr/local/mysql -MN mysql
- 下载解压二进制包并授权创建软连接
#wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
#tar -xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
#ln -s /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64/ /usr/local/mysql
#chown -R mysql.mysql /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64
#chown -R mysql.mysql /usr/local/mysql
- 检查是否缺失库文件
#ldd /usr/local/mysql/bin/mysqld
linux-vdso.so.1 => (0x00007ffed83a5000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd39b12e000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fd39af2a000)
libaio.so.1 => /lib64/libaio.so.1 (0x00007fd39ad28000)
libnuma.so.1 => /lib64/libnuma.so.1 (0x00007fd39ab1c000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fd39a8e5000)
librt.so.1 => /lib64/librt.so.1 (0x00007fd39a6dd000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fd39a3d6000)
libm.so.6 => /lib64/libm.so.6 (0x00007fd39a0d4000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fd399ebe000)
libc.so.6 => /lib64/libc.so.6 (0x00007fd399af0000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd39b34a000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fd3998ed000)
- 创建数据目录并授权
#mkdir /data/mysql/mysql3306/{data,logs,tmp} -p
#chown -R mysql.mysql /data/mysql/
- 配置文件修改
#vim /data/mysql/mysql3306/my3306.cnf
#my.cnf
[client]
port = 3306
socket = /tmp/mysql3306.sock
[mysql]
prompt="u@h [d]>"
#pager="less -i -n -S"
#tee=/opt/mysql/query.log
no-auto-rehash
[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
port = 3306
socket = /tmp/mysql3306.sock
event_scheduler = 0
tmpdir = /data/mysql/mysql3306/tmp
#timeout
interactive_timeout = 300
wait_timeout = 300
#character set
character-set-server = utf8
open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
lower_case_table_names =1
#file
#@secure-file-priv=/tmp
#symi replication
#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=1000 # 1 second
#rpl_semi_sync_slave_enabled=1
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
#binlog
#binlog_format = STATEMENT
binlog_format = row
server-id = 103306
log-bin = /data/mysql/mysql3306/logs/mysql-bin
max_binlog_size = 256M
sync_binlog = 0
expire_logs_days = 10
#procedure
log_bin_trust_function_creators=1
#file
secure_file_priv="/tmp"
#
gtid-mode = on
enforce-gtid-consistency=1
#relay log
skip_slave_start = 1
max_relay_log_size = 128M
relay_log_purge = 1
relay_log_recovery = 1
relay-log=relay-bin
relay-log-index=relay-bin.index
log_slave_updates
#slave-skip-errors=1032,1053,1062
#skip-grant-tables
#buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 128K
join_buffer_size = 128K
thread_cache_size = 200
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 = 100M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:100M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 100M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
- 初始化数据库
#/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize
- 启动数据库
#/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
[1] 11536
- 登录数据库
#cat /data/mysql/mysql3306/data/error.log |grep password
2020-09-03T03:21:38.917473Z 1 [Note] A temporary password is generated for root@localhost: Cb!ytRdJ+6N%
- 修改密码
#/usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock -p'Cb!ytRdJ+6N%'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.30-log
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> alter user user() identified by 'mysql3306';
Query OK, 0 rows affected (0.01 sec)
- 关闭数据库
mysql> shutdown;
Query OK, 0 rows affected (0.00 sec)