2、通过编译、二进制安装MySQL5.7
编译安装MySQL5.7
1:安装相关依赖包
[root@CentOS7 ~]#yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxm12-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper
2:创建用户和准备数据目录
[root@CentOS7 ~]#useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@CentOS7 ~]#mkdir /data/mysql
root@CentOS7 ~]#mkdir -p /usr/local/mysql
[root@CentOS7 ~]#chown mysql.mysql -R /usr/local/mysql
[root@CentOS7 ~]#chown mysql.mysql /data/mysql
3:解压源码包
[root@CentOS7 ~]#tar xf mysql-boost-5.7.25.tar.gz -C /usr/local/mysql
4:源码编译安装
[root@CentOS7 ~]#cd /usr/local/mysql/mysql-5.7.25/
[root@CentOS7 /usr/local/mysql/mysql-5.7.25]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql/boost
[root@CentOS7 /usr/local/mysql/mysql-5.7.25]#make -j 6 && make install -j 6
5:准备环境变量
[root@CentOS7 ~]#echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[root@CentOS7 ~]#. /etc/profile.d/mysql.sh
6:初始化数据库
vim /etc/my.cnf
在[mysqld]写入 explicit_defaults_for_timestamp=1
[root@CentOS7 /usr/local/mysql]#/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
7:准备启动脚本,启动服务
[root@CentOS7 /usr/local/mysql]#/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[root@CentOS7 /usr/local/mysql]#cp support-files/mysql.server /etc/init.d/mysqld
[root@CentOS7 /usr/local/mysql]#chkconfig --add mysqld
[root@CentOS7 /usr/local/mysql]#service mysqld start
二进制安装MySQL5.7
1:安装相关包
[11:37:54 root@CentOS8 ~]\ [#yum -y install libaio numactl-libs
2:创建mysql使用的账号和组
[11:38:39 root@CentOS8 ~]\ [#groupadd mysql
[11:39:15 root@CentOS8 ~]\ [#useradd -r -g mysql -s /bin/false mysql
3:准备程序文件
[11:42:16 root@CentOS8 ~]\ [#tar xvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[11:43:01 root@CentOS8 ~]\ [#cd /usr/local/
[11:43:12 root@CentOS8 local]\ [#ln -s mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[11:44:11 root@CentOS8 local]\ [#chown -R root.root /usr/local/mysql/
4:配置环境变量
[11:44:35 root@CentOS8 local]\ [#echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[11:47:56 root@CentOS8 local]\ [#. /etc/profile.d/mysql.sh
5:准备配置文件
[11:53:27 root@CentOS8 ~]\ [#cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
6:初始化数据库文件生成root随机密码
[12:00:20 root@CentOS8 ~]\ [#mysqld --initialize --user=mysql --datadir=/data/mysql
[12:00:53 root@CentOS8 ~]\ [#grep password /data/mysql/mysql.log
2021-09-11T05:00:51.894111Z 1 [Note] A temporary password is generated for root@localhost: qgp>T985GrTp
7:准备服务脚本和启动
[12:04:39 root@CentOS8 ~]\ [#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[12:05:09 root@CentOS8 ~]\ [#chkconfig --add mysqld
[12:05:21 root@CentOS8 ~]\ [#systemctl start mysqld
8:修改root密码和登录
[12:05:34 root@CentOS8 ~]\ [#mysqladmin -u root -p‘qgp>T985GrTp‘ password magedu
[12:08:03 root@CentOS8 ~]\ [#mysql -uroot -p magedu
3、二进制安装mariadb10.4
1:安装相关包
[root@CentOS7 ~]#yum -y install libaio numactl-libs
2:创建mysql使用的账号和组
[root@CentOS7 ~]#groupadd mysql
[root@CentOS7 ~]#useradd -r -g mysql -s /bin/false mysql
3:准备程序文件
[root@CentOS7 ~]#tar xf mariadb-10.4.11-linux-x86_64.tar.gz -C /usr/local/mysql
[root@CentOS7 ~]#cd /usr/local/mysql
[root@CentOS7 /usr/local/mysql]#ln -s mariadb-10.4.11-linux-x86_64/ mysql
[root@CentOS7 /usr/local/mysql]#chown -R root.root /usr/local/mysql
4:配置环境变量
root@CentOS7 /usr/local/mysql]#echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[root@CentOS7 /usr/local/mysql]#. /etc/profile.d/mysql.sh
5:初始化数据库:
root@CentOS7 /usr/local/mysql/mysql]#mkdir /data/mariadb_data -p
[root@CentOS7 /usr/local/mysql/mysql]#chown root.root /data/mariadb_data -R
6:准备配置文件
[root@CentOS7 /usr/local/mysql]#cd /usr/local/mysql/mariadb-10.4.11-linux-x86_64/
[root@CentOS7 /usr/local/mysql/mariadb-10.4.11-linux-x86_64]#./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
7:准备服务脚本,启动服务
[root@CentOS7 ~]#cp /usr/local/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@CentOS7 ~]#chkconfig --add mysqld
[root@CentOS7 ~]#service mysqld start
Starting mysqld (via systemctl): [ OK ]
原文:https://www.cnblogs.com/zhaoyaxuan/p/15258007.html