MySQL编译安装
一、前言
(一)、概述
MySQL是一个数据库管理系统,也是最流行的关系型数据库管理系统之一,它是由Oracle支持的开源软件;关系数据库将技术保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性;MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言,MySQL软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库。
(二)、预处理
[root@MySQL-1-1 ~]# sed -ri '/^SELINUX=*/cSELINUX=disabled' /etc/selinux/config
[root@MySQL-1-1 ~]# setenforce 0
[root@MySQL-1-1 ~]# systemctl stop firewalld.service
二、安装
(一)、准备环境
准备要使用的文件目录及用户
[root@MySQL-1-1 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
[root@MySQL-1-1 ~]# mkdir /tmp/mysql
[root@MySQL-1-1 ~]# tar xf mysql-5.7.22.tar.gz -C /tmp/mysql
[root@MySQL-1-1 ~]# groupadd mysql
[root@MySQL-1-1 ~]# useradd -r -g mysql -s /bin/nologin mysql
[root@MySQL-1-1 ~]# mkdir /data
(二)、开始编译
root@mysql-1-1 ~]# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make
root@mysql-1-1 ~]# yum -y install cmake
root@mysql-1-1 ~]# cd /tmp/mysql/mysql-5.7.22/
[root@mysql-1-1 mysql-5.7.22]# cmake . \
-DWITH_BOOST=boost_1_59_0 \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1
执行编译安装(这个过程有可能比较长)
[root@mysql-1-1 mysql-5.7.22]# make -j 4 && make install
(三)、启动使用
(1)、准备磁盘
[root@mysql-1-1 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 10G 0 disk
├─vda1 252:1 0 500M 0 part /boot
└─vda2 252:2 0 9.5G 0 part
├─centos-root 253:0 0 6.5G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
vdb 252:16 0 20G 0 disk
[root@mysql-1-1 /]# mkfs.xfs /dev/vdb
meta-data=/dev/vdb isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
(2)、挂载使用
[root@mysql-1-1 ~]# blkid
/dev/vda1: UUID="242c51cd-5466-49d6-95dd-e924f65588de" TYPE="xfs"
/dev/vda2: UUID="PqO6Bn-bq7I-8R3e-KzrR-RFGd-nebU-QfYQ3J" TYPE="LVM2_member"
/dev/vdb: UUID="fa82ce7d-dda3-4085-883c-078a5982d135" TYPE="xfs"
/dev/mapper/centos-root: UUID="00525096-f627-4415-a2dd-862827bc7cec" TYPE="xfs"
/dev/mapper/centos-swap: UUID="4de0a3c7-f591-41f7-96ce-67f148f4f97e" TYPE="swap"
[root@mysql-1-1 ~]# vim /etc/fstab
UUID="fa82ce7d-dda3-4085-883c-078a5982d135" /data xfs defaults 0 0
[root@mysql-1-1 ~]# mount -a
(3)、备份mysql数据
[root@mysql-1-1 ~]# mv /usr/local/mysql /data/
[root@mysql-1-1 ~]# ln -s /data/mysql /var/lib/
[root@mysql-1-1 ~]# ll /usr/local/mysql
lrwxrwxrwx 1 root root 11 Mar 30 18:24 /usr/local/mysql -> /data/mysql
(4)、初始化
[root@mysql-1-1 ~]# cd /usr/local/mysql/ [root@mysql-1-1 mysql]# mkdir mysql-files [root@mysql-1-1 mysql]# chown -R mysql.mysql . [root@mysql-1-1 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2018-07-25T07:57:20.688908Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-07-25T07:57:25.885562Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-07-25T07:57:26.855322Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-07-25T07:57:27.062712Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5f63dd74-8fe0-11e8-9279-52540077021b. 2018-07-25T07:57:27.107357Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-07-25T07:57:27.583041Z 0 [Warning] CA certificate ca.pem is self signed. 2018-07-25T07:57:27.793510Z 1 [Note] A temporary password is generated for root@localhost: i_?IVo!H7Whp
记录i_?IVo!H7Whp 之后用来修改mysql数据库密码
(五)、启动使用
需要拷贝启动脚本到系统
[root@mysql-1-1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@mysql-1-1 mysql]# chkconfig --add mysqld
[root@mysql-1-1 mysql]# chkconfig mysqld on
[root@mysql-1-1 mysql]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql-1-1.err'.
.. SUCCESS!
[root@mysql-1-1 mysql]# ps axu | grep mysqld
root 26423 0.0 0.0 11812 1600 pts/2 S 16:16 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/d
ata --pid-file=/usr/local/mysql/data/mysql-1-1.pid
mysql 26535 8.8 4.2 1731812 168612 pts/2 Sl 16:16 0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr
/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql-1-1.err --pid-file=/usr/local/mysql/data/mys
ql-1-1.pid
添加系统环境
[root@mysql-1-1 bin]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@mysql-1-1 bin]# source /etc/profile
[root@mysql-1-1 bin]# mysqladmin -uroot -p'i_?IVo!H7Whp' password 'Passwd@123'
修改root登录密码,之后就可以使用数据库了。
您的资助是我最大的动力!
金额随意,欢迎来赏!