mysql5.7.30 编译安装

本文参考:http://chenzehe.iteye.com/blog/1266260  感谢原作者的分享!

 

首先安装/更新一些编译时会用到的基础包

[root@localhost local]# yum -y install gcc gcc-c++ make cmake ncurses ncurses-devel libxml2 libxml2-devel openssl-devel bison bison-devel

官网下载mysql 5.7.30版本源码包

编译安装mysql 5.7.30的版本需要gcc支持c++11,不懂的朋友可以看我另外一篇文章:源码安装GCC-4.9.2

 

1、创建mysql用户

[root@localhost local]# groupadd mysql 
[root@localhost local]# useradd -s /sbin/nologin -g mysql -M mysql #不允许mysql用户登录

2、创建数据存放目录

[root@localhost local]# mkdir -pv /data/mysql/dbdata

[root@localhost local]# mkdir -pv /data/mysql/innodb
[root@localhost local]# chown -R mysql.mysql /data/mysql/
#修改目录权限为mysql

3、安装mysql

#官网下载boost文件,解压到当前目录


# 在mysql路径下添加bld文件夹,将编译的文件放在这个文件夹里 mysql-5.7.30
[root@localhost mysql-5.7.30]# mkdir bld

[root@localhost mysql-5.7.30]#

cmake .. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock\
-DSYSCONFDIR=/usr/local/mysql\
-DMYSQL_TCP_PORT=3306\
-DEXTRA_CHARSETS=all\
-DMYSQL_USER=mysql\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_DATADIR=/data/mysql/dbdata\
-DWITH_XTRADB_STORAGE_ENGINE=1\
-DWITH_FEDERATEDX_STORAGE_ENGINE=1\
-DWITH_ARCHIVE_STORAGE_ENGINE=1\
-DWITH_MYISAM_STORAGE_ENGINE=1\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_ARCHIVE_STPRAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DWIYH_READLINE=1\
-DWIYH_SSL=system\
-DVITH_ZLIB=system\
-DWITH_LOBWRAP=0\
-DWITH_BOOST=/usr/local/src/mysql-5.7.30/boost/boost_1_59_0/\
-DDEFAULT_CHARSET=utf8mb4\
-DDEFAULT_COLLATION=utf8mb4_general_ci

 

[root@localhost mysql-5.7.30]# make
[root@localhost mysql-5.7.30]# make install

 到这里MariaDB已经算是安装上了,进行配置就可以使用了。本人在这里用的是多实例配置方法

1、配置文件

# 修改my.cnf文件

[mysqld]
port = 3306
basedir=/usr/local/mysql
datadir=/data/mysql/dbdata
socket=/tmp/mysql.sock

#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
character-set-server = utf8mb4
collation_server = utf8mb4_general_ci
lower_case_table_names =1

[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

 

2、初始化数据目录

  #把用到的工具添加到/usr/bin目录

[root@localhost mysql]# ln -s /usr/local/mysql/scripts/mysql_install_db /usr/bin/mysql_install_db
[root@localhost mysql]# ./bin/mysqld --defaults-file=/etc/my.cnf \

--basedir=/usr/local/mysql/ \
--datadir=/data/mysql/dbdata/ \
--user=mysql \
--initialize-insecure \
--ssl \
--explicit_defaults_for_timestamp \
--verbose

--initialize-insecure 代表不设置密码,空密码进入,   --initialize 设置密码,在日志栏里输出

3、启动数据库

#将/usr/local/mysql/bin加到$PATH环境变量里  
[root@localhost mysql]# vi /etc/profile

export PATH=/usr/local/mysql/bin:$PATH  #插入到最后一行

# 启动 mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld   
[root@localhost mysql]# service mysqld start

在启动的时候会加载innodb,中途不能重启,否则会出现如下错误

151114 00:59:38  mysqld started

151114  0:59:38 [Warning] option 'thread_stack': unsigned value 126976 adjusted to 131072

InnoDB: No valid checkpoint found.

InnoDB: If this error appears when you are creating an InnoDB database,

InnoDB: the problem may be that during an earlier attempt you managed

InnoDB: to create the InnoDB data files, but log file creation failed.

InnoDB: If that is the case, please refer to

InnoDB: http://dev.mysql.com/doc/refman/5.0/en/error-creating-innodb.html

151114  0:59:38 [ERROR] Default storage engine (InnoDB) is not available

151114  0:59:38 [ERROR] Aborting

151114  0:59:38 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

151114 00:59:38  mysqld ended

 

删除innodb文件夹,重新启动就可以了

 

# mysql5.7.30 错误集锦

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

上面这个错误是由于 mysql没有初始化密码,执行以下语句即可
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
mysql> flush privileges;

 

  

 
posted @ 2020-06-28 10:10  1011110  阅读(1452)  评论(0编辑  收藏  举报