yum 安装MySQL
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -ri s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld
[root@localhost ~]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo
# 修改(5.7:enabled=1 gpgcheck=0 8.0:enabled=0)
[root@localhost ~]# yum -y install mysql-community-server
[root@localhost ~]# systemctl start mysqld && systemctl enable mysqld
[root@localhost ~]# grep "password" /var/log/mysqld.log
[root@localhost ~]# mysql -uroot -p
[root@localhost ~]# alter user ‘root’@’localhost’ identified by “password”;
源码编译安装MySQL
[root@localhost ~]# yum -y update
[root@localhost ~]# yum -y groupinstall "Development Tools"
[root@localhost ~]# yum -y install ncurses ncurses-devel bison libgcrypt perl make cmake
[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -M -g mysql -s /sbin/nologin mysql
[root@localhost ~]# mkdir -p /usr/local/mysqld/{data,mysql,log,tmp}
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysqld/*
[root@localhost ~]# tar xf mysql-boost-5.7.24.tar.gz
[root@localhost ~]# cd mysql-5.7.24
[root@localhost ~]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysqld/mysql \
-DMYSQL_DATADIR=/usr/local/mysqld/data \
-DWITH_BOOST=/opt/mysql-5.7.24/boost \
-DDEFAULT_CHARSET=utf8
#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysqld/mysql -DMYSQL_DATADIR=/usr/local/mysqld/data -DWITH_BOOST=/opt/mysql-5.7.24/boost -DDEFAULT_CHARSET=utf8
[root@localhost ~]# make -j `lscpu | awk 'NR==4{ print $2 }'`
[root@localhost ~]# make install
#提升MySQL命令为系统级别命令--添加环境变量
#专业配置环境变量PATH的文件:/etc/profile
#专业配置环境变量PATH的文件子项/etc/profile.d/
[root@localhost ~]# vim /etc/profile.d/mysqlcimmand.sh
#添加:export PATH=$PATH:/usr/local/mysqld/mysql/bin
[root@localhost ~]# source /etc/profile
[root@localhost ~]# echo $PATH
#拷贝默认配置文件至/etc/my.cnf中
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysqld/*
[root@localhost ~]# cd /usr/local/mysqld/mysql/mysql-test/include
[root@localhost ~]# mv /etc/{my.cnf,my.cnf.bak}
[root@localhost ~]# cp default_my.cnf /etc/my.cnf
[root@localhost ~]# vim /etc/my.cnf
# Use default setting for mysqld processes
!include default_mysqld.cnf
!include default_client.cnf
[mysqld]
basedir = /usr/local/mysqld/mysql
datadir = /usr/local/mysqld/data
tmpdir = /usr/local/mysqld/tmp
socket = /usr/local/mysqld/tmp/mysql.sock
pid_file = /usr/local/mysqld/tmp/mysqld.pid
log_error = /usr/local/mysqld/log/mysql_error.log
slow_query_log_file = /usr/local/mysqld/log/slow_warn.log
server_id = 19216816110
user = mysql
port = 3306
bind-address = 0.0.0.0
character-set-server = utf8
default_storage_engine = InnoDB
#执行数据库服务初始化操作
[root@localhost ~]# mysqld --defaults-file=/etc/my.cnf --initialize --user='mysql'
#启动mysqld服务
[root@localhost ~]# mysqld_safe --defaults-file=/etc/my.cnf & #首次需要安全启动
#查看默认密码:
[root@localhost ~]# grep password /usr/local/mysqld/log/mysql_error.log
#建立sock文件软链接:
[root@localhost ~]# ln -s /usr/local/mysqld/tmp/mysql.sock /tmp/mysql.sock
#登录:
[root@localhost ~]# mysql -uroot -p
#配置mysqld服务的管理工具
[root@localhost ~]# cd /usr/local/mysqld/mysql/support-files/
[root@localhost ~]# cp mysql.server /etc/init.d/mysqld #开机初始化时执行
[root@localhost ~]# chkconfig --add mysqld #加入到开机启动的列表
[root@localhost ~]# chkconfig mysqld on #开启
#创建mysqlctl
[root@localhost ~]# cp /usr/local/mysqld/mysql/support-files/mysql.server /usr/local/mysqld/mysql/bin/mysqlctl
启动:mysqlctl start
停止:mysqlctl stop
源码安装MySQL的流程:
- 更新系统内部RPM软件,并安装开发工具组,以及相应的编译依赖软件
- 创建MySQL用户为MySQL服务设置用户身份;设置mysqld服务安装的目录
- 解压mysql源码包 >> 预编译(cmake) >> 编译(make) >> 安装(make install)
- 添加mysql/bin下的命令至系统级别 >> 添加MySQL命令至环境变量中
- 将配置文件放置到/etc/my.cnf中;编写配置文件
- 对mysql服务进行初始化操作
- 使用mysql_safe进行安全启动;预加载安装选项;
- 设置客户端与服务端连接的socket文件至/tmp
- 登录mysql服务端,修改密码
- 设置开机自启脚本;设置mysqld服务控制指令