mysql源码安装
环境说明:
操作系统:redhat7.0
mysql版本:mysql-5.7.26
1.关闭防火墙以及selinux
[root@lwq-client ~]# systemctl stop firewalld
[root@lwq-client ~]# systemctl disable firewalld
[root@lwq-client ~]# getenforce
Disabled
2.在官网上下载mysql,boost包
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.26.tar.gz
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
3.安装依赖包
[root@lwq-client ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio
4.解压安装包
tar zxvf:
z:表示tar包是被gzip压缩过的,所以解压时需要用gunzip解压
x:从tar包中把文件提取出来
v:显示详细信息
f:f xxx.tar.gz : 指定被处理文件是xxx.tar.gz
[root@lwq-client ~]# tar xzvf mysql-5.7.26.tar.gz
[root@lwq-client ~]# tar -zxvf boost_1_59_0.tar.gz
[root@lwq-client ~]# ls
anaconda-ks.cfg boost_1_59_0.tar.gz mysql-5.7.26 boost_1_59_0 initial-setup-ks.cfg mysql-5.7.26.tar.gz
[root@lwq-client ~]# mv mysql-5.7.26 mysql-5.7.26.tar.gz /usr/src/
[root@lwq-client ~]#mv boost_1_59_0 /usr/local/boost
5.创建mysql用户和组
[root@lwq-client ~]# groupadd -r mysql
[root@lwq-client ~]# useradd -M -s /sbin/nologin -g mysql mysql
[root@lwq-client ~]# id mysql
uid=991(mysql) gid=1001(mysql) 组=1001(mysql)
6.编译安装mysql
[root@lwq-client ~]# cd /usr/src/
[root@lwq-client src]# ls
boost_1_59_0 debug kernels mysql-5.7.26 mysql-5.7.26.tar.gz
[root@lwq-client src]# cd mysql-5.7.26/
[root@lwq-client 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 //注意cmake 后都要接“-”
[root@lwq-client mysql-5.7.26]# make && make install
7.修改目录权限
[root@lwq-client ~]# chown -R mysql.mysql /usr/local/mysql
[root@lwq-client ~]# chmod -R 755 /usr/local/mysql/
[root@lwq-client ~]# ll -d /usr/local/mysql/
drwxr-xr-x 10 mysql mysql 186 8月 17 19:36 /usr/local/mysql/
8.建立数据存放目录
[root@lwq-client ~]# mkdir -p /data/mysql
[root@lwq-client ~]# chown -R mysql.mysql /data/mysql/
[root@lwq-client ~]# ll -d /data/mysql/
drwxr-xr-x 2 mysql mysql 6 8月 17 19:52 /data/mysql/
9.初始化数据库
[root@lwq-client ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2019-08-17T11:59:24.597262Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-17T11:59:25.016927Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-17T11:59:25.067712Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-17T11:59:25.165701Z 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: 75219377-c0e6-11e9-bf78-000c29b10852.
2019-08-17T11:59:25.166486Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-17T11:59:25.167264Z 1 [Note] A temporary password is generated for root@localhost: FqIf)yk5Asr#
//注意:这里的密码是随机的,此处密码是FqIf)yk5Asr#
10.生成配置文件并修改mysql
//将源服务器配置文件移动备份或删除
[root@lwq-client ~]# mv /etc/my.cnf{,.bak}
[root@lwq-client ~]# cd /usr/src/mysql-5.7.26/
[root@lwq-client mysql-5.7.26]# vim /etc/my.cnf
[root@lwq-client 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
11.配置mysql服务
[root@lwq-client ~]# cd /usr/local/mysql/support-files/
[root@lwq-client support-files]# cp mysql.server /etc/init.d/mysqld
[root@lwq-client support-files]# chmod -R 755 /etc/init.d/mysqld
[root@lwq-client support-files]# ll -d /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10576 8月 17 20:07 /etc/init.d/mysqld
12.修改文件存放路径 启动mysql服务
[root@lwq-client ~]# vim /etc/init.d/mysqld
//搜索basedir和datadir,添加:
basedir=/usr/local/mysql/
datadir=/data/mysql/
[root@lwq-client ~]# service mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/data/mysql/lwq-client.err'.
SUCCESS!
[root@lwq-client ~]# ps -ef | grep mysql
root 25238 1 0 20:12 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql 25416 25238 1 20:12 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=lwq-client.err --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 25448 2231 0 20:12 pts/1 00:00:00 grep --color=auto mysql
[root@lwq-client ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 127.0.0.1:6011 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 ::1:6011 :::*
LISTEN 0 80 :::3306 :::*
13.登陆mysql
//先使用临时密码登陆
[root@lwq-client ~]# /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> set password = password('lwq'); //修改密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
//用修改后的密码登陆
[root@lwq-client ~]# /usr/local/mysql/bin/mysql -uroot -plwq
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> //登陆成功