mysql5.7源码安装数据库部署

**mysql5.7.20源码部署

作者:mj培根(mjboy)**

1)安装基础包
yum install -y gcc gcc-c++ automake autoconf git make
yum -y install cmake bison-devel ncurses-devel libaio-devel

2)创建目录(用于存放下载文件)
mkdir -p /home/mjboy/tools

下载mysql5.7.20至此/home/mjboy/tools目录
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.20.tar.gz
wget https://downloads.mysql.com/archives/get/file/mysql-boost-5.7.20.tar.gz

3)创建mysql用户:
groupadd -g 800 mysql
useradd -u 800 mysql -s /sbin/nologin -M -g mysql

4)tar解压包
tar xf mysql-5.7.20.tar.gz
tar xf mysql-boost-5.7.20.tar.gz

5)cmake配置编译选项
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.20 \
-DMYSQL_DATADIR=/application/mysql-5.7.20/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.7.20/tmp/mysql.sock \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/home/mjboy/tools/mysql-5.7.20/boost \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0

注意:utf8mb4是utf8的超集,但一般utf8够用了,而且utf8mb4会消耗更多空间

参数具体含义:
参考官方文档--cmake mysql5.7参考
https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

6)编译 && 安装
make && make install

7)设置mysql软链接
ln -s /application/mysql-5.7.20/ /application/mysql

思考:为什么要设置软链接--(版本更换,提供便利)

8)拷贝启动文件及配置文件(如果没有,则自己创建,最好自己制作my.cnf)

设置mysqld启动脚本

cp /application/mysql-5.7.20/support-files/mysql.server /etc/init.d/mysqld

#配置my.cnf

cp /application/mysql-5.7.20/support-files/my-default.cnf /etc/my.cnf

[root@mysql57 ~]# cat /etc/my.cnf
[client]
port = 3306
socket = /application/mysql/data/tmp/mysql.sock

#这个配置段设置启动MySQL服务的条件;在这种情况下,no-auto-rehash确保这个服务启动得比较快。
#no-auto-rehash

[server]
user = root
port = 3306
socket = /application/mysql/data/tmp/mysql.sock
basedir = /application/mysql
datadir = /application/mysql/data/

9)设置环境变量

[root@master data]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@master data]# tail -1 /etc/profile
[root@master data]# export PATH=/application/mysql/bin:$PATH
[root@master data]# source /etc/profile
[root@master data]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

注意:为什么要把application的环境变量放在前面?
http://oldboy.blog.51cto.com/2561410/1122867(环境变量位置先后的影响)

10)授权
chown -R mysql:mysql /application/mysql/data/
chmod -R 1777 /tmp/

11)初始化
/application/mysql-5.7.20/bin/mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.20/ --datadir=/application/mysql-5.7.20/data

#初始密码记录下来
#A temporary password is generated for root@localhost: NphU.;4Xdl#w

12)创建mysql.sock存放目录,并授权
mkdir /application/mysql-5.7.20/tmp
chown -R mysql.mysql /application/mysql-5.7.20/

13)启动
/etc/init.d/mysqld start或者systemctl start mysqld

14)修改初始密码
mysqladmin -uroot -p'NphU.;4Xdl#w' password 'root'

15)登录mysql成功!
[root@mysql57 ~]# mysql -uroot -proot -e "select version();show databases;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 5.7.20 |
+-----------+
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| tmp |
+--------------------+
[root@mysql57 ~]#

转载于:https://blog.51cto.com/moonwalk/2113700

你可能感兴趣的:(mysql5.7源码安装数据库部署)