码迷,mamicode.com
首页 > 数据库 > 详细

Centos7系统编译安装Mysql5.7.21

时间:2018-05-02 18:07:16      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:mysql centos7

环境说明 :

centos7.4 64位虚拟机 

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


[root@localhost ~]# 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用户的临时密码(最后一行);

[root@localhost mysql-5.7.21]# chown -R mysql:mysql /usr/local/mysql

[root@localhost mysql-5.7.21]# cd /usr/local/mysql/bin/

[root@localhost 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 root@localhost: 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 root@localhost = password('123456');


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


Centos7系统编译安装Mysql5.7.21

标签:mysql centos7

原文地址:http://blog.51cto.com/mofansheng/2110911

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!