MySQL安装部署——centos7
(本节重点: MySQL的两种安装方法 ①yum安装MySQL②二进制安装MySQL)
一、yum安装MySQL(有两种方法)
1.方法一:
下载rpm包:https://dev.mysql.com/downloads/mysql/
注意:该方法安装时,虽然安装包下载到了本地,但是安装的过程中存在依赖,因此要修改安装网络源来接触依赖。
安装步骤:
1.卸载mariadb(linux默认的数据库)
[root@localhost ~]#rpm -e mariadb-libs postfix
2.安装
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql #添加MySQL用户组,和用户
[root@localhost ~]# mkdir mysql
[root@localhost ~]#tar xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar.tar -C mysql (解压-C:指定目录)
3.启动
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enable mysqld #开机启动
4.查看默认密码在修改密码
方法二:官方源安装(速度慢)
https://dev.mysql.com/downloads/repo/yum/
[root@localhost ~]# yum install mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# yum list |grep "mysql-community"
[root@localhost ~]# yum install mysql-community-client mysql-community-server
二、通用二进制安装
1.下载glibc版本的mysql
http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-8.0/
2.安装系统依赖包
[root@localhost ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel readline-devel libaio-devel perl libaio wget lrzsz vim libnuma* bzip2 xz
3.关闭selinux
[root@localhost ~]# setenforce 0 #暂时关闭
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' #永久关闭
4.修改配置文件的参数
[root@localhost ~]# vim /etc/security/limits.conf
5.修改内核的参数
[root@localhost ~]# sysctl -p #立即生效
5.mysql的安装配置
(1)解压安装包
[root@localhost ~]# tar xjf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz -C /opt/
(2)做软连接到/usr/bin
[root@localhost ~]# cd /opt/
[root@localhost opt]# cd /usr/local/
[root@localhost local]# ln -s /opt/mysql-8.0.19-linux-glibc2.12-x86_64 mysql/
(3)创建用户
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql -d /home/mysql -s /sbin/nologin
(4)修改目录权限
[root@localhost local]# chown -R mysql.mysql mysql/*
(5)初始化数据库
[root@localhost local]# cd mysql/
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
(6)创建配置文件,配置文件若存在需要先注释
[root@localhost mysql]# if [ -f /etc/my.cnf ]; then mv /etc/my.cnf "/etc/my.cnf. `date +%Y%m%d%H%m`.bak"; fi
(7)修改配置文件
[root@localhost profile.d]# vim /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.logsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
(8)为MySQL提供sysv服务脚本
[root@localhost profile.d]# 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
(9)启动MySQL
[root@localhost mysql]# chkconfig --add mysqld --添加为系统服务
[root@localhost mysql]# chkconfig mysqld on --开机自启动
[root@localhost mysql]# systemctl start mysqld
(10)将MySQL的bin目录加入PATH环境变量,编辑/etc/profile文件,使用mysql客户端命令
[root@localhost ~]# cd /etc/profile.d/
[root@localhost ~]# vim mysql.rcexport PATH=$PATH:/usr/local/mysql/bin #添加这一条
root@localhost ~]# source mysql.sh
(11)数据库登录并改密码
[root@localhost mysql]# 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 - GPLCopyright (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.
mysql> alter user 'root'@'localhost' identified by 'ABC123.com'; #修改密码为ABC23.com
本文地址:https://blog.csdn.net/xiangmomo1/article/details/107307192
上一篇: Linux环境C++ 实战项目 小型搜索引擎(基于RSS)
下一篇: js实现幻灯片轮播图