[MySQL] standardized installation tutorial

Keywords: MySQL Linux RPM socket

Guidance:
This article mainly introduces the installation steps of MySQL 5.7.23 binary installation of CentOS system, and the installation process of other versions is similar.

1. Preparation

  • Uninstall old MySQL

    • View the rpm package

    rpm -qa|grep mysql if available

    • Find mysql residue package, delete if any, and ignore if no

    find / -name mysql

  • Installation dependent

    yum -y install make gcc-c++ cmake bison-devel ncurses-devel numactl libaio

  • Create users and user groups

    groupadd mysql
    useradd -s /sbin/nologin -g mysql -M mysql

2. Download the binary installation package and extract it

cd /usr/local/
# wget download or upload after local download
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# Unzip the installation package
tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# After decompression, for the convenience of later operation, you can change the filename after decompression to mysql
mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql
# Change folder ownership
chown -R mysql.mysql /usr/local/mysql/

3. Create mysql related directories

mkdir -p /data/mysql/{data,logs,tmp}
# Change folder ownership
chown -R mysql.mysql /data/mysql/

4. Create mysql configuration file my.cnf

vi /etc/my.cnf
# The simple template is as follows:
[client]
port            = 3306
socket          = /data/mysql/tmp/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql        
datadir = /data/mysql/data  
port = 3306               

socket = /data/mysql/tmp/mysql.sock
pid-file  = /data/mysql/tmp/mysqld.pid
tmpdir = /data/mysql/tmp    
skip_name_resolve = 1
symbolic-links=0
max_connections = 2000
group_concat_max_len = 1024000
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1
log_timestamps=SYSTEM
character-set-server = utf8
interactive_timeout = 1800  
wait_timeout = 1800
max_allowed_packet = 32M
binlog_cache_size = 4M
sort_buffer_size = 2M
read_buffer_size = 4M
join_buffer_size = 4M
tmp_table_size = 96M
max_heap_table_size = 96M
max_length_for_sort_data = 8096

#logs
server-id = 1003306
log-error = /data/mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 3
log-bin = /data/mysql/logs/binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
relay-log = /data/mysql/logs/relay-bin
relay-log-recovery = 1  
relay_log_purge = 1  

#innodb  
innodb_file_per_table = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_flush_method = O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_size = 2G

5. Configure mysql.server

cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
# Modify directory location
basedir=/usr/local/mysql
datadir=/data/mysql/data

# Register startup service
chkconfig --add mysql
chkconfig --list

6. Add environment variable

echo "PATH=$PATH:/usr/local/mysql/bin  " >> /etc/profile  
source /etc/profile

7. Initialize mysql

/usr/local/mysql/bin/mysqld  --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
# The temporary password is saved in errlog 
# Get temporary password
more /data/mysql/logs/error.log |grep password

8. Start mysql service and change password

# service mysql start 
service mysql start
# Log in to mysql service with the initial password and change the password
mysql -uroot -p
alter user 'root'@'localhost' identified by 'root';
flush privileges;

Posted by patsfans on Sun, 08 Dec 2019 13:12:06 -0800