Centos7.6安装mysql8.0

下载

MySQL Product Archives<MySQL Community Server (Archived Versions)

cd /opt && wget wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.31-el7-x86_64.tar
tar -xvf /opt/mysql-8.0.31-el7-x86_64.tar
cd /usr/local && tar -zxvf /opt/mysql-8.0.31-el7-x86_64.tar.gz
mv mysql-8.0.31-el7-x86_64 mysql

关闭防火墙

# 检查防火墙状态
systemctl status firewalld.service
# 暂时关闭防火墙,下次启动时防火墙仍随系统启动而启动
systemctl stop firewalld.service
# 彻底永久关闭防火墙
systemctl disable firewalld.service
# 关闭SELINUX防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

修改/etc/hosts文件

echo '124.71.201.84 hw-m1' >> /etc/hosts

卸载mariadb

rpm -qa | grep mysql 
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps

创建用户和目录

mkdir -p /data/mysql/data
mkdir -p /data/mysql/log
mkdir -p /data/mysql/log-bin
useradd mysql
passwd mysql
chown -R mysql.mysql /data/mysql
chown -R mysql.mysql /usr/local/mysql

创建my.cnf文件

echo '
[mysqld]
# GENERAL #
user = mysql
collation_server=utf8mb4_general_ci
character_set_server=utf8mb4
default-storage-engine = InnoDB
socket = /data/mysql/data/mysql.sock
pid-file = /data/mysql/data/mysql.pid
port = 3306
# SAFETY #
max_allowed_packet = 16M
max_connect_errors = 1000000
skip_name_resolve
# DATA STORAGE #
datadir = /data/mysql/data/
long_query_time = 1
# BINARY LOGGING #
binlog-format = ROW
log-bin = /data/mysql/log-bin/mysql-bin-3306
expire-logs-days = 14
sync-binlog = 1
max_binlog_size = 500M
# CACHES AND LIMITS #
tmp_table_size = 32M
max_heap_table_size = 32M
max_connections = 500
thread_cache_size = 50
open_files_limit = 65535
table_definition_cache = 4096
table_open_cache = 4096
# INNODB #
innodb_data_file_path = ibdata1:128M;ibdata2:10M:autoextend
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 2
innodb_lock_wait_timeout = 50
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table = 1
innodb_thread_concurrency = 8
innodb_buffer_pool_size = 8G
# LOGGING #
log-error = /data/mysql/log/mysql-error-3306.log
log-queries-not-using-indexes = 1
slow-query-log = 1
long_query_time = 1
slow-query-log-file = /data/mysql/log/mysql-slow-3306.log
server-id = 1
[client]
default_character-set=utf8mb4' > /etc/my.cnf

配置系统服务

cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql/data

/etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
# 检查是否成功
chkconfig mysqld --list

添加环境变量

echo 'export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin' >> /etc/profile
source /etc/profile

初始化数据库

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
# 报错
# /usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
# 安装libaio库
yum -y install libaio*
# 再重新初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
systemctl start mysqld
ln -s /data/mysql/data/mysql.sock /tmp/mysql.sock

登录

# 查看root密码
grep 'root@localhost' /data/mysql/log/mysql-error-3306.log |  awk -F'root@localhost: ' '{print $2}'
mysql -uroot -p"wjGEMSrmN5)a"
# 修改数据库密码
alter user user() identified by "root";
flush privileges;
# 创建用户
create user 'root'@'%' identified by 'root';
# 授权
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sqlboy-yuzhenc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值