MySQL数据库の安装(三种方法)

MySQL的安装

(安装版本8以上)
一、rpm包安装

  • yum源安装
    简单,但是速度慢
    yum源文件
    yum install 就可以了

  • 下载rmp包安装
    mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar

  • 配置yum源
    安装过程中可能会存在依赖,修改安装网络源来解除依赖。
    安装阿里镜像源
    阿里源

  • 卸载Mariadb
    rpm -e mariadb-libs postfix

  • 安装mysql

groupadd mysql
useradd -g mysql mysql
mkdir mysql
tar xf mysql-8.0.18-1.el7.x86_64.rpm-bundle\ \(1\).tar -C mysql
cd mysql
yum localinstall mysql-community-client-8.0.18-1.el7.x86_64.rpm mysql-community-server-8.0.18-1.el7.x86_64.rpm mysql-community-libs-8.0.18-1.el7.x86_64.rpm mysql-community-common-8.0.18-1.el7.x86_64.rpm
  • 启动
    systemctl start mysqld
    找到root默认密码
    grep “temporary password” /var/log/mysqld.log

  • 修改密码
    使用默认密码登录以后首先要改密码,之后才能进行操作

mysql> alter user 'root'@'localhost'IDENTIFIED BY 'ABC123@com';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

二、通用二进制安装

  • 下载glibc版本的mysql
    下载地址

  • 安装依赖包

yum install -y make gcc-c++ cmake bison-devel ncurses-devel readline-devel libaio-devel perl libaio wget lrzsz libnuma* bzip2 xz
  • 处理selinux
vim /etc/selinux/config
SELINUX=disabled

setenforce 0
  • 修改系统限制参数
[root@sr2 ~]# vim /etc/security/limits.conf
###custom
#
* soft   nofile       20480
* hard   nofile       65535
* soft   nproc        20480
* hard   nproc        65535

  • 修改内核参数
[root@sr2 ~]# vim /etc/sysctl.conf
vm.swappiness=0
#增加tcp支持的队列数
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@sr2 ~]# sysctl -p

  • 安装配置
    解压
[root@sr2 ~]# tar xf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz /opt/
   做软连接
[root@sr2 ~]# ln -s /opt/mysql-8.0.15-linux-glibc2.12-x86_64/ /usr/local/mysql
    用户创建
[root@sr2 ~]# groupadd mysql 
[root@sr2 ~]# useradd -g mysql mysql -d /home/mysql -s /sbin/nologin

    修改权限
[root@sr2 ~]# chown -R mysql.mysql mysql/*
   初始化数据库 (初始化数据库后在后面会生成个密码,记住这个密码,用它来进入数据库)
[root@sr2 ~]# cd /usr/loacl/mysql/
[root@sr2 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
  • 注释掉原有的配置文件(那是mariadb的配置文件)
[root@sr2 ~]# if [ -f /etc/my.cnf ]; then mv /etc/my.cnf "/etc/my.cnf.`date +%Y%m%d%H%m`.bak"; fi
  • 创建配置文件
[root@sr2 ~]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
#skip-grant-tables
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服务添加到系统服务中
cd /usr/local/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
  • 启动
chkconfig  --add mysqld
chkconfig  mysqld on
systemctl start mysqld
  • 加入环境变量
[root@sr2 ~]# cd /etc/profile.d/
[root@sr2 profile.d]# vim mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@sr2 profile.d]# source mysql.sh
  • 登录之后修改密码

你可能感兴趣的:(MySQL数据库の安装(三种方法))