文章目录
源码安装
关闭防火墙
[root@zhangwumysql ~]# systemctl stop firewalld
[root@zhangwumysql ~]# systemctl disable firewalld
[root@zhangwumysql ~]# getenforce
Disabled
登入官网下载所需要安装的包
[root@zhangwumysql ~]wget https://downloads.mysql.com/archives/get/file/mysql-5.7.26.tar.gz
[root@zhangwumysql ~]wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@zhangwumysql ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio
解压安装包
[root@zhangwumysql ~]# tar xzvf mysql-5.7.26.tar.gz
[root@zhangwumysql ~]# tar -zxvf boost_1_59_0.tar.gz
[root@zhangwumysql ~]# 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@zhangwumysql ~]# mv mysql-5.7.26 mysql-5.7.26.tar.gz /usr/src/
[root@zhangwumysql ~]#mv boost_1_59_0 /usr/local/boost
创建用户和组
[root@zhangwumysql ~]# groupadd -r mysql
[root@zhangwumysql ~]# useradd -M -s /sbin/nologin -g mysql mysql
编译安装mysql
[root@zhangwumysql ~]# cd /usr/src/
[root@zhangwumysq lsrc]# ls
boost_1_59_0 debug kernels mysql-5.7.26 mysql-5.7.26.tar.gz
[root@zhangwumysql src]# cd mysql-5.7.26/
[root@zhangwumysql 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@zhangwumysql mysql-5.7.26]# make && make install
修改目录权限
[root@zhangwumysql ~]# chown -R mysql.mysql /usr/local/mysql
[root@zhangwumysql ~]# chmod -R 755 /usr/local/mysql/
初始化数据库
[root@zhangwumysql ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2019-08-17T14:32:24.662388Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-17T14:32:25.662399Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-17T14:32:25.073257Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-17T14:32:25.763859Z 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-17T14:32:25.651302Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-17T14:32:25.503468Z 1 [Note] A temporary password is generated for root@localhost: FqIf)ky7Cha#
将源服务器配置文件移动备份或删除
[root@zhangwumysql ~]# mv /etc/my.cnf{,.bak}
修改mysql配置
[root@zhangwumysql ~]# cd /usr/src/mysql-5.7.26/
[root@lwq-client mysql-5.7.26]# vim /etc/my.cnf
[root@zhangwumysql 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
修改配置文件
[root@zhangwumysql ~]# cd /usr/local/mysql/support-files/
[root@zhangwumysql support-files]# cp mysql.server /etc/init.d/mysqld
[root@zhangwumysql support-files]# chmod -R 755 /etc/init.d/mysqld
修改文件存放路径
[root@zhangwumysql ~]# vim /etc/init.d/mysqld
查找basedir修改文件路径
basedir= /usr/local/mysql/
datadir= /opt/data
启动服务
[root@zhangwumysql ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
root 37369 1 0 20:47 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/lihuaixin.pid
mysql 37256 273898 0 20:48 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/opt/data/error.log --pid-file=/opt/data/lihuaixin.pid --socket=/tmp/mysql.sock
root 37268 1923 0 20:53 pts/1 00:00:00 grep --color=auto mysql
使用临时密码登录与修改密码
[root@zhangwumysql ~]# /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('zhangwu931');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
登入
[root@zhangwumysql ~]# /usr/local/mysql/bin/mysql -uroot -p 'zhangwu931'
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.