http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-8.0/
yum -y install make gcc-c++ cmake bison-devel ncurses-devel readline-devel libaio-devel perl libaio wget lrzsz vim libnuma* bzip2 xz
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
vim /etc/security/limits.conf
#
###custom
#
* soft nofile 20480
* hard nofile 65535
* soft nproc 20480
* hard nproc 65535
[root@localhost ~]# vi /etc/sysctl.conf
[root@localhost ~]# sysctl -p
vm.swappiness = 0
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_max_tw_buckets = 8000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_fin_timeout = 30
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.core.wmem_default = 87380
net.core.wmem_max = 16777216
net.core.rmem_default = 87380
net.core.rmem_max = 16777216
解压安装包
[root@localhost ~]# tar xJf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz -C /opt/
做软连接到/usr/bin
[root@localhost ~]# cd /opt/
[root@localhost opt]# cd /usr/local/
[root@localhost local]# ln -s /opt/mysql-8.0.15-linux-glibc2.12-x86_64 mysql
创建用户
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql -d /home/mysql -s /sbin/nologin
修改目录权限
[root@localhost local]# chown -R mysql.mysql mysql/*
初始化数据库
注意记住数据库初始密码(2019-07-20T22:01:10.814007Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost:
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-07-20T22:01:08.025261Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-07-20T22:01:08.025410Z 0 [System] [MY-013169] [Server] /opt/mysql-8.0.15-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.15) initializing of server in progress as process 1721
2019-07-20T22:01:10.814007Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost:
创建配置文件,配置文件若存在,需要先注释。
mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%m`.bak
修改配置文件
[root@localhost mysql]# vi /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server_id=10
port = 3306
user = mysql
character-set-server = utf8
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysqld.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#####====================================[innodb]==============================
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:10M:autoextend
#####====================================[log]==============================
log_error = /var/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql-slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
为mysql提供sysv服务脚本
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
启动mysql
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# systemctl start mysqld
将mysql的bin目录加入PATH环境变量,编辑/etc/profile文件 使用mysql客户端命令
[root@localhost mysql]# cd /etc/profile.d/
[root@localhost profile.d]# vim mysql.sh
[root@localhost profile.d]# source mysql.sh
数据库登录并修改密码
[root@localhost ~]# mysql -uroot -p
Enter password:
登录进去然后修改密码
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
[root@localhost ~]# mysql -uroot -p123456