mysql源码安装

1.在官网上下载mysql,boost包

[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

2.关闭防火墙和selinux

[root@xiaobai ~]# systemctl stop firewalld
[root@xiaobai ~]# systemctl disable firewalld
[root@xiaobai ~]# getenforce 
Disabled

3.安装依赖包

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

4.解压安装包到相应目录

[root@xiaobai ~]# tar -zxvf mysql-5.7.26.tar.gz 
[root@xiaobai ~]# tar -zxvf boost_1_59_0.tar.gz
[root@xiaobai ~]# ls
anaconda-ks.cfg  mysql-5.7.26  mysql-5.7.26.tar.gz  boost_1_59_0  boost_1_59_0.tar.gz
[root@xiaobai ~]# mv mysql-5.7.26  mysql-5.7.26.tar.gz /usr/src
[root@xiaobai ~]# mv boost_1_59_0 /usr/local/boost

5.创建mysql用户和组

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

6.编译安装mysql

[root@xiaobai ~]# cd mysql-5.7.26
[root@xiaobai 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@xiaobai mysql-5.7.26]# make && make install

7.修改目录权限

[root@xiaobai ~]# chown -R mysql:mysql /usr/local/mysql/
[root@xiaobai ~]# chmod -R 755 /usr/local/mysql/
[root@xiaobai ~]# ll /usr/local/
drwxr-xr-x. 10 mysql mysql  186 8月  17 14:55 mysql

8.建立数据存放目录

[root@xiaobai ~]# mkdir -p /data/mysql
[root@xiaobai ~]# chown -R mysql.mysql /data/mysql/
[root@xiaobai ~]# ll /data/
总用量 0
drwxr-xr-x. 5 mysql mysql 166 8月  17 16:38 mysql

9.初始化数据库

[root@xiaobai ~]# cd /usr/local/mysql/
[root@xiaobai mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2019-08-17T08:26:26.928658Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-17T08:26:26.928731Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2019-08-17T08:26:26.928735Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2019-08-17T08:26:27.781811Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-17T08:26:27.859536Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-17T08:26:27.934521Z 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: b54ed196-c0c8-11e9-a4f0-000c29cb3ee9.
2019-08-17T08:26:28.146976Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-17T08:26:28.148697Z 1 [Note] A temporary password is generated for root@localhost: 4lEMk3Lb3c!j
//注意:这里的密码是随机的,此处密码是4lEMk3Lb3c!j

10.生成配置文件

//将原服务器配置文件移动备份或删除
[root@xiaobai ~]# mv /etc/my.cnf{,.bak}

11.修改mysql配置

[root@xiaobai ~]# cd /usr/src/mysql-5.7.26
[root@xiaobai mysql-5.7.26]# vim /etc/my.cnf
[root@xiaobai mysql-5.7.26]# cat /etc/my.cnf
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
pid-file = /data/mysql/mysql.pid
socket = /tmp/mysql.sock
character-set-server=utf8

[mysql_safe]
log-error=/data/mysql/error.log
pid-file=/data/mysql/mysql.pid

12.配置服务启动脚本

[root@xiaobai ~]# cd /usr/local/mysql/support-files/
[root@xiaobai support-files]# cp mysql.server /etc/init.d/mysqld
[root@xiaobai support-files]# chmod 755 /etc/init.d/mysqld 

13.修改文件存放路径

[root@xiaobai ~]# vim /etc/init.d/mysqld 
//搜索basedir、datadir,在后面添加下面目录
basedir=/usr/local/mysql/
datadir=/data/mysql/

14.启动mysql服务

[root@xiaobai ~]# service mysqld restart
Shutting down MySQL. SUCCESS! 
Starting MySQL. SUCCESS!
[root@xiaobai ~]# ps -ef|grep mysql
root      42463      1  0 16:31 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql     42643  42463  0 16:31 pts/1    00:00:00 /usr/local/mysql/bin/mysqd --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=xiaobai.err --pid-file=/data/mysqlmysql.pid --socket=/tmp/mysql.sock --port=3306
root      42674  41594  0 16:33 pts/1    00:00:00 grep --color=auto mysql
[root@xiaobai ~]# 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                  :::*            

15.使用临时密码登录

 [root@xiaobai ~]# /usr/local/mysql/bin/mysql -uroot -p
    Enter password: 
    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> 

16.修改密码

mysql> set password = password('xiaobai123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

17.登录验证

[root@xiaobai ~]# /usr/local/mysql/bin/mysql -uroot -p'xiaobai123';
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> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值