mysql--二进制安装编译安装yum安装
二进制安装
创建用户和组
[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# useradd -r -g 306 -u 306 -d /data/mysql mysql
创建文件夹并添加所属文件用户和组
[root@localhost ~]# mkdir -p /data/mysql
[root@localhost ~]# chown mysql:mysql /data/mysql
导入安装包并进行解压
[root@localhost ~]# tar -zxvf /usr/bin/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz -C /usr/local
创建软链接
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.6.51-linux-glibc2.12-x86_64 mysql
设置权限
[root@localhost local]# chown -R root:root /usr/local/mysql/
准备配置文件
[root@localhost local]# cd /usr/local/mysql
[root@localhost mysql]# cp -b support-files/my-default.cnf /etc/my.cnf
创建数据库文件
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
出现报错
解决
[root@localhost mysql]# yum-y install autoconf
查看文件
root@localhost mysql]# ls /data/mysql/ -l
准备启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
报错
解决
[root@localhost mysql]# mkdir /var/log/mariadb
[root@localhost mysql]# touch /var/log/mariadb/mariadb.log
[root@localhost mysql]# chown -R mysql:mysql /var/log/mariadb/
[root@localhost mysql]# service mysql start
#如果有对应的service 文件可以执行下面
cp /usr/local/mysql/support-files/systemd/mariadb.service
/usr/lib/systemd/system/
systemctl daemon-reload
systemctl enable --now mariadb
PATH路径
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
chmod 777 /etc/profile.d/mysql.sh
./etc/profile.d/mysql.sh
安全初始化
/usr/local/mysql/bin/mysql_secure_installation
编译安装
环境准备
yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper
创建用户
[root@localhost ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql
创建目录并修改权限
[root@localhost ~]# mkdir -p /data/mysql
[root@localhost ~]# chown mysql:mysql /data/mysql
导入安装包并解压
[root@localhost ~]# tar -zxvf mysql-5.6.51.tar.gz -C /usr/local/src
源码编译安装 MySQL
cd /usr/local/src/mysql-5.6.51/
cmake . \ -DCMAKE_INSTALL_PREFIX=/apps/mysql \ -DMYSQL_DATADIR=/data/mysql/ \ -DSYSCONFDIR=/etc/ \ -DMYSQL_USER=mysql \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \ -DWITH_DEBUG=0 \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_LIBWRAP=0 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci
make && make install
配置环境变量
[root@localhost mysql-5.6.51]#echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# chmod 777 /etc/profile.d/mysql.sh
[root@localhost ~]# /etc/profile.d/mysql.sh
生成数据库文件
[root@localhost ~]# cd /apps/mysql/
[root@localhost mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
准备配置文件
[root@localhost mysql]# cp -b /apps/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# chkconfig --add mysql
[root@localhost mysql]# service mysqld start
安全初始化
/usr/local/mysql/bin/mysql_secure_installation
yum源安装
配置mysql的yum源
[root@VM-0-14-rockylinux ~]# tee /etc/yum.repos.d/mysql.repo << EOF
> [MYSQL]
> name=mysql
> baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64
> gpgcheck=0
> EOF
yum安装mysql
yum -y install mysql-community-server
设置开机自启动
systemctl enable --now mysqld