Mysql8.0安装
一、环境准备:
1.目录创建:
mkdir -p /data/{software,mysql}
mkdir -p /data/mysql/{data,log,tmp}
2.用户创建:
useradd mysql
3.安装依赖包:
yum install perl perl-devel perl-Data-Dumper libaio-devel -y
二、安装:
1.下载包文件:
cd /data/software/
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
xz -d mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar
ln -s /data/software/mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql
2.权限赋值:
chown -R mysql:mysql /usr/local/mysql /data/mysql/*
三、配置文件:
参数可以根据实际需求进行调配
vi /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/tmp/mysql.sock
[mysql]
prompt="\u@db \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql/data
socket = /data/mysql/tmp/mysql.sock
pid-file = /data/mysql/tmp/mysql.pid
character-set-server=utf8mb4
collation-server = utf8mb4_general_ci
sql_mode='NO_UNSIGNED_SUBTRACTION,NO_ENGINE_SUBSTITUTION'
open_files_limit = 65535
innodb_open_files = 65535
back_log=1024
max_connections = 512
max_connect_errors=1000000
interactive_timeout=300
wait_timeout=300
max_allowed_packet = 1024M
secure_file_priv=''
log-error=/data/mysql/log/error.log
slow_query_log=ON
slow_query_log_file=/data/mysql/log/slow_mysql.log
long_query_time=2
innodb_flush_log_at_trx_commit=1
innodb_log_file_size =1G
innodb_log_files_in_group=3
innodb_log_group_home_dir=./
log-bin-trust-function-creators=1
sync_binlog = 1
binlog_cache_size = 16M
max_binlog_cache_size = 1G
max_binlog_size=1G
expire_logs_days = 30
log-bin= /data/mysql/log/binlog-mysql
binlog_format=row
binlog_row_image=full
server-id = 1
default_authentication_plugin =mysql_native_password
# 大小根据实际系统内存情况而定
innodb_buffer_pool_size=4G
innodb_buffer_pool_instances=2
四、初始化
1初始化操作
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql --initialize
#查看初始化后数据库文件:
[root@localhost log]# ls /data/mysql/data
auto.cnf ca.pem client-key.pem ibdata1 ib_logfile1 #innodb_temp mysql.ibd private_key.pem server-cert.pem sys undo_002
ca-key.pem client-cert.pem ib_buffer_pool ib_logfile0 ib_logfile2 mysql performance_schema public_key.pem server-key.pem undo_001
2查看随机密码:可以看到我们的初始密码为 qsD#h/qwP4p?
[root@localhost redis]# cat /data/mysql/log/error.log | grep password
2020-01-15T09:13:45.120512Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qsD#h/qwP4p?
五、最后我们启动mysql:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
六、修改密码,设置环境变量以及自启动
# 配置环境变量
[root@localhost log]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
[root@localhost ~]# source /etc/profile
# 修改密码
[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -uroot -p password
Enter password:
New password:
Confirm new password:
# 设置自启动
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on
# 登入Mysql
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@db 17:48: [(none)]>
最后修改时间:2021-08-16 09:32:43
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




