编译安装mysql

关闭防火墙

[root@xiaoxiong ~]# systemctl stop firewalld
[root@xiaoxiong ~]# systemctl disable firewalld
[root@xiaoxiong ~]# setenforce 0

下载源码安装包

[root@xiaobai ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.26.tar.gz
[root@xiaobai ~]# wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

安装依赖包

[root@xiaoxiong ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio

解压包到指定目录

[root@xiaoxiong ~]# tar xf mysql-5.7.26.tar.gz -C /usr/local
[root@xiaoxiong ~]# cd /usr/local/
[root@xiaoxiong local]# mkdir boost
[root@xiaoxiong ~]# tar xf boost_1_59_0.tar.gz -C /usr/local/boost

编译安装mysql

[root@xiaoxiong mysql-5.7.26]# cd /usr/local/mysql-5.7.26/
root@xiaoxiong mysql-5.7.26]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost -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=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EMBEDDED_SERVER=1
[root@xiaoxiong mysql-5.7.26]# make && make install

创建用户组及用户

[root@xiaoxiong ~]# groupadd -r mysql
[root@xiaoxiong ~]# useradd -M -s /sbin/nologin -g mysql mysql

修改目录权限

[root@xiaoxiong ~]#  chown -R mysql.mysql /usr/local/mysql
[root@xiaoxiong ~]# chmod -R 755 /usr/local/mysql
[root@xiaoxiong ~]# ll /usr/local/
总用量 4
drwxr-xr-x.  2 root  root     6 3月  10 2016 bin
drwxr-xr-x.  3 root  root    26 8月  17 18:01 boost
drwxr-xr-x.  2 root  root     6 3月  10 2016 etc
drwxr-xr-x.  2 root  root     6 3月  10 2016 games
drwxr-xr-x.  2 root  root     6 3月  10 2016 include
drwxr-xr-x.  2 root  root     6 3月  10 2016 lib
drwxr-xr-x.  2 root  root     6 3月  10 2016 lib64
drwxr-xr-x.  2 root  root     6 3月  10 2016 libexec
drwxr-xr-x. 10 mysql mysql  186 8月  17 19:33 mysql
drwxr-xr-x. 37  7161 31415 4096 8月  17 19:33 mysql-5.7.26
drwxr-xr-x.  2 root  root     6 3月  10 2016 sbin
drwxr-xr-x.  5 root  root    49 7月   3 23:24 share
drwxr-xr-x.  2 root  root     6 3月  10 2016 src

建立存放目录

[root@xiaoxiong ~]# mkdir /data
[root@xiaoxiong ~]# chown -R mysql.mysql /data

初始化数据库

[root@xiaoxiong ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data
2019-08-17T12:12:01.417299Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-17T12:12:01.805880Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-17T12:12:01.866478Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-17T12:12:01.925984Z 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: 383208d1-c0e8-11e9-9c5d-000c29676c62.
2019-08-17T12:12:01.926812Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-17T12:12:01.928903Z 1 [Note] A temporary password is generated for root@localhost: aNhBUsr3,m<<
结尾会生成一个随机密码,保存下来
[root@xiaoxiong ~]# echo "aNhBUsr3,m<<" > pass

生成配置文件

[root@xiaoxiong ~]# cat > /etc/my.cnf < [mysqld]
> basedir = /usr/local/mysql
> datadir = /data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@xiaoxiong ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data
socket = /tmp/mysql.sock
port = 3306
pid-file = /data/mysql.pid
user = mysql
skip-name-resolve

配置服务启动脚本

[root@xiaoxiong ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@xiaoxiong ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@xiaoxiong ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

启动mysql服务

[root@xiaoxiong ~]# service mysqld restart
Shutting down MySQL. SUCCESS! 
Starting MySQL. SUCCESS!
[root@xiaoxiong ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128        *:22                     *:*                  
LISTEN     0      100    127.0.0.1:25                     *:*                  
LISTEN     0      128       :::22                    :::*                  
LISTEN     0      100      ::1:25                    :::*                  
LISTEN     0      80        :::3306                  :::* 

修改密码

利用初始化给的随机密码登陆mysql
[root@xiaoxiong ~]# cat pass 
aNhBUsr3,m<<
[root@xiaoxiong ~]# /usr/local/mysql/bin/mysql -uroot -p'aNhBUsr3,m<<''
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26
    
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
    
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit

登陆验证

[root@xiaoxiong ~]# /usr/local/mysql/bin/mysql -uroot -p'123456';
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

你可能感兴趣的:(编译安装mysql)