CentOS 7环境安装二进制(glibc)MySQL 8.0.24

官网二进制安装包下载地址:
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz

安装MySQL
1、解压MySQL安装包
[root@szl-46 ~]# tar -xvJf mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz

2、重命名文件并移动到/usr/local/mysql/目录下
[root@szl-46 ~]# mv mysql-8.0.24-linux-glibc2.12-x86_64 /usr/local/mysql

3、为MySQL添加用户组和用户
3.1添加用户组
[root@szl-46 ~]# groupadd mysql

3.2添加用户
[root@szl-46 ~]# useradd -r -g mysql mysql

4、检查是否安装libaio
[root@szl-46 ~]# rpm -qa | grep libaio
libaio-0.3.109-13.el7.x86_64
libaio-devel-0.3.109-13.el7.x86_64

若没有则执行如下命令进行安装:
[root@szl-46 ~]# yum -y install libaio

5、在/etc目录下添加my.cnf文件
[root@szl-46 ~]# cat >> /etc/my.cnf <<EOF
[mysql]
default_character_set=utf8mb4

[mysqld]
port = 3306
server_id = 12131401
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log_bin = /usr/local/mysql/log/mysql-bin
relay_log = /usr/local/mysql/log/mysql-relay
innodb_log_group_home_dir = /usr/local/mysql/log
tmpdir = /tmp
log_error=/usr/local/mysql/log/error.log
report_host = 10.186.61.40

# BINLOG
binlog_error_action = ABORT_SERVER
binlog_format = row
binlog_checksum = NONE
binlog_rows_query_log_events = 1
log_slave_updates = 1
master_info_repository = TABLE
max_binlog_size = 250M
relay_log_info_repository = TABLE
relay_log_recovery = 1
sync_binlog = 1

# GTID
gtid_mode = ON
enforce_gtid_consistency = 1

# ENGINE
default_storage_engine = InnoDB
innodb_buffer_pool_size = 128M
innodb_data_file_path = ibdata1:1G:autoextend
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit=1
innodb_flush_method = O_DIRECT
innodb_io_capacity = 200
innodb_log_buffer_size = 64M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_max_dirty_pages_pct = 60
innodb_print_all_deadlocks=1
innodb_stats_on_metadata = 0
innodb_strict_mode = 1

# CACHE
tmp_table_size = 32M
table_open_cache = 1024
max_connections = 1000
thread_cache_size = 1024
open_files_limit = 65535

# SLOW LOG
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/mysql/log/mysql-slow.log
log_slow_admin_statements = 1
log_slow_slave_statements = 1

6、创建data和log目录
[root@szl-46 ~]# mkdir /usr/local/mysql/{data,log}
[root@szl-46 ~]# cd /usr/local/mysql

7、修改当前目录/usr/local/mysql用户为mysql
[root@szl-46 mysql]# chown -R mysql:mysql /usr/local/mysql

8、初始化MySQL
[root@szl-46 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

配置MySQL
1、设置开机启动
复制启动脚本到资源目录
[root@szl-46 mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

增加MySQL服务控制脚本权限
[root@szl-46 mysql]# chmod +x /etc/rc.d/init.d/mysqld

将mysqld服务加入到系统服务
[root@szl-46 mysql]# chkconfig --add mysqld

检查mysqld服务是否已经生效
[root@szl-46 mysql]# chkconfig --list mysqld

2、启动MySQL
[root@szl-46 ~]# systemctl start mysqld

3、环境变量配置
将MySQL的bin目录加入到PATH环境变量:
[root@szl-46 ~]# cat >> /etc/profile <<EOF
export MYSQL_HOME=/usr/local/mysql
export PATH=\$PATH:\$MYSQL_HOME/bin
EOF
source /etc/profile

登录MySQL
1、登录MySQL
[root@szl-46 ~]# grep "temporary password" /usr/local/mysql/log/error.log
mysql -h127.0.0.1 -uroot -p(登录密码为初始化的时候显示的临时密码,可以在MySQL错误日志里查看到)

2、修改初始化密码,不然不能进行其他操作,修改语句如下:
mysql> alter user root@'localhost' identified by 'mysql';

3、开启防火墙端口3306使其可远程访问
[root@szl-46 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

4、开启数据库远程连接
mysql> create user root@'%' identified by 'mysql';
grant all privileges on *.* to 'root'@'%';
alter user root@'%' identified with mysql_native_password by 'mysql';
flush privileges;

[root@szl-46 ~]# mysql -h 192.168.6.98 -uroot -p

上一篇:Linux 部署apache2.4


下一篇:46. 定义带参数的装饰器