Centos7系统编译安装Mysql5.7.21

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7系统编译安装Mysql5.7.21相关的知识,希望对你有一定的参考价值。

环境说明 :

centos7.4 64位虚拟机 

mysql5.7.21.tar.gz 编译安装需要虚拟机2G内存


[[email protected] ~]# uname -a

Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


安装步骤如下:

1、安装依赖包:

yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake


2、建立用户,授权安装目录和数据目录权限

groupadd mysql

useradd -g mysql -s /bin/false -M mysql

mkdir -p /data/mysql/

mkdir /usr/local/mysql

chown -R mysql:mysql /data/mysql/


3、下载boost

5.7版本需要下载一个Boost C++ 1.59.0(这是一组扩充C++功能的经过同行评审(Peer-reviewed)且开放源代码程序库。大多数的函数为了能够以开放源代码、封闭项目的方式运作,而授权于Boost软件许可协议(Boost Software License)之下。)

# mkdir /usr/local/boost

# cd /usr/local/src/

# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

# tar -xvf boost_1_59_0.tar.gz

# mv boost_1_59_0/* /usr/local/boost/


4、编译安装mysql

# cd /usr/local/src

# tar -xvf mysql-5.7.21.tar.gz

# cd mysql-5.7.21

# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

# make

# make install


5、mysql执行命令加入系统环境变量

# echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile

# source /etc/profile


6、授权安装目录,初始化;

初始化完毕请注意打印信息会提示root用户的临时密码(最后一行);

[[email protected] mysql-5.7.21]# chown -R mysql:mysql /usr/local/mysql

[[email protected] mysql-5.7.21]# cd /usr/local/mysql/bin/

[[email protected] bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/

2018-04-19T16:03:21.925384Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-04-19T16:03:22.973102Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-04-19T16:03:23.079720Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-04-19T16:03:23.138367Z 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: 2fb233d4-43eb-11e8-ba3b-000c29783bcc.

2018-04-19T16:03:23.139384Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-04-19T16:03:23.140005Z 1 [Note] A temporary password is generated for [email protected]: ioiqC=s(d8zq


7、修改my.cnf 配置文件

# cat /etc/my.cnf

[mysqld]

datadir = /data/mysql

socket = /usr/local/mysql/mysql.sock

log_error = /data/mysql/mysql-error.log


8、启动mysql

方法1:

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# chmod 755 /etc/init.d/mysqld

# chkconfig --add mysqld

# chkconfig mysqld on

# /etc/init.d/mysqld start

Starting MySQL. SUCCESS!

# ps -ef |grep mysql

root      20321      1  0 17:26 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid

mysql     20461  20321 11 17:26 pts/0    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=/data/mysql/mysql-error.log --pid-file=/data/mysql/localhost.localdomain.pid --socket=/usr/local/mysql/mysql.sock


方法2:

# mysqld_safe --defaults-file=/etc/my.cnf &


9、输入执行初始化命令打印的最后一行临时密码,登陆数据库,第一次登陆提示要更改密码才可以进行操作;

# mysql -uroot -p

mysql> use mysql;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> set password for [email protected] = password('123456');


如果错过打印的临时密码,可以使用--skip-grant-tables 进行重新设置密码;


以上是关于Centos7系统编译安装Mysql5.7.21的主要内容,如果未能解决你的问题,请参考以下文章

centos7上安装mysql5.7.21流程

CENTOS7上安装MYSQL5.7.21流程

centos7 yum安装mysql5.7

MySQL5.7.21解压版安装详细教程

CentOS6.9安装mysql5.7.21教程

中标麒麟操作系统安装mysql5.7.21