1.MySQL官网下载安装包:
MySQL :: Download MySQL Community Server
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
2.解压文件:
#tar xvzf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
3.移动文件:
#mkdir /usr/local/mysql
#mv mysql-5.7.39-linux-glibc2.12-x86_64/* /usr/local/mysql
4.配置操作系统:
#useradd mysql
#mkdir -p /data/mysql
#chown -R mysql:mysql /usr/local/mysql/
#chown -R mysql:mysql /data/mysql
#chmod -R 777 /usr/local/mysql/
#chmod -R 777 /data/mysql
5.编辑MySQL配置文件:
#vi /etc/my.cnf
[client]
port=3306
socket=/data/mysql/mysql.sock
[mysqld]
gtid_mode=on
enforce_gtid_consistency=on
log_slave_updates=on
autocommit=1
general_log=off
explicit_defaults_for_timestamp=true
log_timestamps = SYSTEM
#character
default-storage-engine=INNODB
innodb_file_per_table=1
character-set-server=utf8
collation-server=utf8_general_ci
interactive_timeout = 559200
wait_timeout = 559200
#system
basedir=/usr/local/mysql
datadir=/data/mysql
max_allowed_packet=1g
max_connections=3000
max_user_connections=2800
open_files_limit=65535
pid_file=/data/mysql/mysqld.pid
port=3306
server_id=52160
#skip_name_resolve=ON
socket=/data/mysql/mysql.sock
tmpdir=/tmp
#undo
innodb_undo_tablespaces=3
#innodb
innodb_buffer_pool_size = 1000M
#binlog
log_bin=/data/mysql/bin-log
binlog_format=row
expire_logs_days=7
innodb_log_file_size = 1024M
innodb_log_files_in_group = 4
max_binlog_size=1024M
#logging
log_error=/data/mysql/error.log
slow_query_log_file=/data/mysql/slow.log
log_queries_not_using_indexes=0
slow_query_log=1
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1
#relay
relay_log=/data/mysql/relaylog
relay_log_index=/data/mysql/relay.index
relay_log_info_file=/data/mysql/relay-log.info
[mysqld_safe]
datadir=/data/mysql
6.初始化数据库:
#su - mysql
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
7.配置和启动数据库:
#cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
8.客户端登录MySQL数据库:
/usr/local/mysql/bin/mysql -h localhost -uroot –p
#初次登录的临时密码在/data/mysql/error.log 文件中
9.修改密码:
alter user root@'localhost' identified by 'mySQL#1234';
10.关闭数据库:
/etc/init.d/mysqld stop
11.设置开机自动启动:
#chkconfig mysqld on
注意:
ps -ef|grep mysqld 可以查看mysql进程是否已经启动
kill -9 进程号 #杀死进程