mysql安装常见的方法有四种
序号 | 安装方式 | 说明 |
1 | yum\rpm | 简单、快速,不能定制参数 |
2 | 二进制 | 解压,简单配置就可使用 免安装 mysql-a.b.c-linux2.x-x86_64.tar.gz |
3 | 源码编译 | 可以定制参数,安装时间长 mysql-a.b.c.tar.gz |
4 | 源码制成rpm包 | 把源码制作成符合要求的rpm,通过yum安装 |
MySQL RPM包下载
官网下载地址:
https://dev.mysql.com/downloads/mysql/
1. yum安装依赖包
yum -y install lrzsz wget perl-Digest-MD5
yum -y install numactl
yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make
添加用户及组
[root@jeames ~]# groupadd mysql
删除组:groupdel users
--用户加到组并指定根目录
[root@jeames ~]# useradd -g mysql -d /home/mysql mysql
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
删除用户:userdel mysql
[root@jeames ~]# passwd mysql
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
安装Mysql
[root@jeames ~]# md5sum mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar
edf4d0f95867f62cdcc97b7349bedc59 mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar
[root@jeames ~]# tar -xvf mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar -C /home/mysql/
## 必须安装的四个RPM包
mysql-community-common-8.0.27-1.el8.x86_64.rpm
mysql-community-libs-8.0.27-1.el8.x86_64.rpm
mysql-community-client-8.0.27-1.el8.x86_64.rpm 是客户端的安装包
mysql-community-server-8.0.27-1.el8.x86_64.rpm 是服务端的安装包
## 授权
root@jeames ~]# chown -R mysql:mysql /home/mysql/
## 安装
注:root用户下操作
[root@jeames ~]# cd /home/mysql/
装顺序:包之间相互依赖,所以必须注意安装顺序
✓ 先装 common
✓ 再装 libs
✓ 再装 client
✓ 最后装 server
[root@jeames mysql]# rpm -ivh mysql-community-common-8.0.27-1.el8.x86_64.rpm
[root@jeames mysql]# rpm -ivh --force --nodeps mysql-community-libs-8.0.27-1.el8.x86_64.rpm
[root@jeames mysql]# rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm --force --nodeps
[root@jeames mysql]# rpm -ivh mysql-community-server-8.0.27-1.el8.x86_64.rpm --f
2 Linux环境二进制安装MySQL
MySQL二进制包下载
官网下载地址:https://dev.mysql.com/downloads/mysql/
安装 MySQL
## 用户及目录创建
注:可以部署多个实例,通过端口区分root 用户操作:
mkdir -p /mysql/data/mysql3306
mkdir -p /mysql/app/
mkdir -p /mysql/conf/
mkdir -p /mysql/data/mysql3306/pid/
mkdir -p /mysql/data/mysql3306/socket/
mkdir -p /mysql/data/mysql3306/log/
mkdir -p /mysql/data/mysql3306/binlog/
mkdir -p /mysql/data/mysql3306/errlog
mkdir -p /mysql/data/mysql3306/relaylog/
mkdir -p /mysql/data/mysql3306/slowlog/
mkdir -p /mysql/data/mysql3306/tmp/
## 用户及组
[root@rhel76 ~]# groupadd mysql
[root@rhel76 ~]# useradd -g mysql mysql
[root@rhel76 ~]# chown -R mysql:mysql /mysql
[root@rhel76 ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@rhel76 ~]# cat /etc/group | grep mysql
mysql:x:1001:
[root@rhel76 ~]# cat /etc/passwd | grep mysql
mysql:x:1001:1001::/home/mysql:/bin/bash
## 上传软件包并解压
[root@rhel76 ~]# cp mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz /mysql/app
[root@rhel76 ~]# chown -R mysql:mysql /mysql
mysql用户操作
[root@rhel76 ~]# su - mysql
md5 值验证,保证下载到的软件包无破损无木马
[mysql@rhel76 ~]$ cd /mysql/app
[mysql@rhel76 app]$ ll
total 1168588
-rw-r--r-- 1 mysql mysql 1196633756 Nov 24 00:49 mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
[mysql@rhel76 app]$ md5sum mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
0bdd171cb8464ba32f65f7bf58bc9533 mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
解压软件包并重命名
[mysql@rhel76 app]$ tar xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
[mysql@rhel76 app]$ mv mysql-8.0.27-linux-glibc2.12-x86_64 mysql8.0.27
[mysql@rhel76 app]$ ll
total 1168588
drwxrwxr-x 9 mysql mysql 129 Nov 24 00:54 mysql8.0.27
-rw-r--r-- 1 mysql mysql 1196633756 Nov 24 00:49 mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
Linxu环境源码安装MySQL
Mysql源码下载
官网下载地址:https://dev.mysql.com/downloads/mysql/
安装及配置
## 编译
[root@jeames007 ~]# mkdir /soft
[root@jeames007 ~]# mv mysql-boost-8.0.27.tar.gz /soft/
[root@jeames007 ~]# cd /soft
[root@jeames007 soft]# tar -zxf mysql-boost-8.0.27.tar.gz
[root@jeames007 soft]# ll
total 285340
drwxr-xr-x 31 7161 31415 4096 Sep 28 13:22 mysql-8.0.27
-rw-r--r-- 1 root root 292184025 Nov 25 15:08 mysql-boost-8.0.27.tar.gz
[root@jeames007 soft]# cd mysql-8.0.27
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/soft/mysql-8.0.27/boost/boost_1_73_0 \
-DFORCE_INSOURCE_BUILD=1
[root@jeames007 ~]# make -j4 --此处编译需要1个小时,一定要耐心等待
[root@jeames007 ~]# make install
## 用户及组
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
## 参数文件
cat > /etc/my.cnf <<"EOF"
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
server_id=80273306
log-bin
skip-name-resolve
character_set_server=utf8mb4
default-time-zone = '+8:00'
log_timestamps = SYSTEM
EOF
## 初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
## 环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /root/.bashrc
source /root/.bashrc
## 启动Mysql
#启动 MySQL
mysqld_safe &
#登录 mysql,默认密码为空
mysql -uroot -p
#关闭 MySQL
mysqladmin -uroot -p shutdown