centos 6.5 x64安装mysql 5.7

Posted

tags:

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

mysql 5.7最新版本下载


http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12.tar.gz


在编译之前,确保已经安装了epel更新源

安装了编译环境

yum groupinstall -y "Development tools"


mysql 5.7编译cmake要求版本最低为2.8

升级cmake

yum -y install ncurses-devel cmake

mysql 5.7编译需要boost类库

下载地址:


http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download


创建用户和用户组

groupadd mysql

useradd -g mysql mysql

usermod -s /sbin/nologin mysql

创建目录

mkdir -p /data/3306/data /data/3306/logs

解压软件包

tar zxvf mysql-5.7.12.tar.gz -C /usr/src

cd /usr/src/mysql-5.7.12

编译

cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/data/3306/data \

-DMYSQL_TCP_PORT=3306 \

-DMYSQL_UNIX_ADDR=/data/3306/mysqld.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DEXTRA_CHARSETS=all \

-DWITH_EMBEDDED_SERVER=1 \

-DWITH_SSL=bundled \

-DWITH_DEBUG=0 \

-DENABLE_DOWNLOADS=1 \

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/root/boost_1_59_0.tar.gz


安装

make

make install


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

在这里特别提醒,对于mysql5.7的make编译,如果是云主机,会在make编译到45%时会报错,这是内存不足所致


c++: Internal error: Killed (program cc1plus)

Please submit a full bug report.

See <http://bugzilla.redhat.com/bugzilla> for instructions.

make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc.cc.o] Error 1

make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2

make: *** [all] Error 2


创建2G的交换分区

dd if=/dev/zero of=/swapfile bs=1k count=2048000 --获取要增加的2G的SWAP文件块

mkswap /swapfile     -- 创建SWAP文件

swapon /swapfile     -- 激活SWAP文件

swapon -s            -- 查看SWAP信息是否正确


出错后重新运行配置,需要删除CMakeCache.txt文件

make clean

rm -f CMakeCache.txt


重新运行

cmake -DCMAKE_INSTALL_PREFIX**************** 参数


编译完后, 如果不想要交换分区了, 可以删除:

swapoff /swapfile

rm -fr /swapfile

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


初始化

/usr/local/mysql/scripts/mysql_install_db \

--basedir=/usr/local/mysql \

--datadir=/data/3306/data \

--user=mysql

编辑配置文件

cd /usr/local/mysql

cp my.cnf my.cnf.bak

vi my.cnf

删除注视行,添加如下内容:


 basedir = /usr/local/mysql

 datadir = /data/3306/data

 port = 3306

 server_id = 2

 socket = /data/3306/mysqld.sock

 pid-file = /data/3306/mysql.pid

 max_allowed_packet=16M

 log-error = /data/3306/logs/error.log


设置文件权限

chown mysql:mysql -R /data/3306 /usr/local/mysql

复制启动脚本

cp /usr/src/mysql-5.6.23/support-files/mysql.server /etc/init.d/mysqld

添加脚本权限,加入开机自启动

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --level 2345 mysqld on

编辑环境变量

vi /etc/profile

最后一行添加

PATH=$PATH:/usr/local/mysql/bin

重新加载环境变量

source /etc/profile

启动数据库

/etc/init.d/mysqld start


初始化

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data


以root初始化操作时要加–user=mysql参数,生成一个随机密码(注意保存登录时用)


2016-05-26T09:30:27.839300Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2016-05-26T09:30:29.769641Z 0 [Warning] InnoDB: New log files created, LSN=45790

2016-05-26T09:30:30.051308Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2016-05-26T09:30:30.145629Z 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: 7cd43705-2324-11e6-9f04-5254001c11ad.

2016-05-26T09:30:30.153626Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.

2016-05-26T09:30:30.163438Z 1 [Note] A temporary password is generated for [email protected]: &iiaod5Z/f:H


以上信息可以看到随机密码为 &iiaod5Z/f:H

备份配置文件

cd /etc/

mv my.cnf my.cnf.bak

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

编辑配置文件

vi my.cnf


 basedir = /usr/local/mysql

 datadir = /data/3306/data

 port = 3306

 server_id = 2

 socket = /data/3306/mysqld.sock

 pid-file = /data/3306/mysql.pid

 max_allowed_packet=16M

 log-error = /data/3306/logs/error.log


chown mysql:mysql -R /data/3306 /usr/local/mysql

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

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --level 2345 mysqld on

编辑环境变量

vi /etc/profile

最后一行添加

PATH=$PATH:/usr/local/mysql/bin

重新加载环境变量,启动mysql

source /etc/profile

/etc/init.d/mysqld start

进入Mysql

mysql -u root -p

输入密码: &iiaod5Z/f:H

必须修改密码,否则提示

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

修改密码为root

alter user ‘root‘@‘localhost‘ identified by ‘root‘;

quit;


再次进入

mysql -u root -proot

执行命令,就可以了

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)



本文出自 “陨落星空” 博客,请务必保留此出处http://xiao987334176.blog.51cto.com/2202382/1783509

以上是关于centos 6.5 x64安装mysql 5.7的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 6.5/6.6 安装(install)mysql 5.7 最完整版教程

centos 6.5 mysql 5.7.11安装流程

CentOS-6.5(X64)使用yum安装LAMP环境

centos 6.5 x64安装php 7

centos 6.5 安装oracle 11g x64

centos 6.5 x64安装Tengine