mysql8.0.12源码_MySQL8.0.12源码编译安装_centos7.3

源码编译安装MySQL8.0.12_centos7.3

--下载mysql8.0.12

https://dev.mysql.com/downloads/mysql/

Archives中选择归档版本,MySQL Community Server:Operating System选择Source Code

0.前期准备条件

#cmake3需要手工下载

#yum -y install gcc gcc-c++ ncurses-devel openssl-devel cmake3 bison wget bzip2

yum install ncurses-devel

yum install bison

#1.cmake的源编译安装

nohup tar zxvf cmake-3.11.1.tar.gz &

cd cmake-3.11.1

./configure

gmake && make install

ldonfig

#2.wolfssl包的部署安装[可选项],可以不配置

*. 从wolfssl.com网站下载wolfssl-3.13.0.zip压缩包

*. 解压至/opt/mysql-8.0.11/extra/wolfssl-3.13.0目录中。

*. cd wolfssl-3.14.0/IDE/MYSQL

*. 执行do.sh脚本

*. use -DWITH_SSL=wolfssl for CMake

#3.openssl和openssl-devel[本实验使用的是system ssl]

yum install –y openssl openssl-devel

#4.mysql的编译安装

cd /opt

tar zxvf mysql-8.0.12.tar.gz

cd /opt/mysql-8.0.11/

mkdir Zdebug

cd Zdebug

systemctl restart network

--不指定-DDOWNLOAD_BOOST时需要把boost_1_67_0.tar.gz上传到/usr/local/src,mysql8.0.11需要boost_1_66_0.tar.gz

#cmake时注意不要添加如下storage_engine

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \

#cmake过程中需要从服务器下载组件,mysql5.7开始编译时不需要指定storage_engine,否则报错:deprecated behivor

#> /opt/mysql-8.0.11/Zdebug/mysql_cmake80.log,加此选项也有可能报错:deprecated behivor

#-DDOWNLOAD_BOOST=1下载boost,若下载过程中出错则再次尝试,若已手工下载则不需要指定-DDOWNLOAD_BOOST=1

cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNODB_MEMCACHED=ON \

-DWITH_SSL=system \

-DCOMPILATION_COMMENT="zyj_zsd edition" \

-DWITH_BOOST=/usr/local/src \

-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock \

-DSYSCONFDIR=/data/mysqldata/3306

#参考,mysql8.0.12执行

#上传mysql8.0.12到/usr/local/src,并解压

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_DEBUG=0 -DWITH_INNODB_MEMCACHED=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_PROFILING=0 -DCMAKE_C_FLAGS="-O3" -DCMAKE_CXX_FLAGS="-O3"

--tail -f /opt/mysql-8.0.11/Zdebug/mysql_cmake80.log

#出现下列日志:

#说明编译成功,其中-DWITH_SSL=system用的是linux操作系统的openssl,需要安装openssl和openssl-devel包,才可以被编译

-- Configuring done

-- Generating done

-- Build files have been written to: /opt/mysql-8.0.11/Zdebug

#如果需要编译安装快速,可以运用多线程加快编译安装,命令如下:

#报错:c++: internal compiler error: Killed (program cc1plus);解决:内存不足,执行make

make -j 12

make install

#MySQL 8.0的软件目录结构

ls -l /usr/local/mysql/

#5.创建mysql用户&并修改相关文件

groupadd mysql

useradd -g mysql mysql

passwd mysql

#6.设置用户操作系统资源的限制

vi /etc/security/limits.conf

mysql soft nproc 65536

mysql hard nproc 65536

mysql soft nofile 65536

mysql hard nofile 65536

#7.创建MySQL数据目录及赋予相应权限

mkdir -p /usr/local/mysql

mkdir -p /data/mysqldata/{3306/{data,tmp,binlog,innodb_ts,innodb_log},backup,scripts}

chown -R mysql:mysql /data/mysqldata

su - mysql

#8.配置my.cnf文件,应该用utf8字符集,innodb_deadlock_detect 应为off

vi /data/mysqldata/3306/my.cnf

[client]

port = 3306

socket = /data/mysqldata/3306/mysql.sock

# The MySQL server

[mysqld]

port = 3306

user = mysql

socket = /data/mysqldata/3306/mysql.sock

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

basedir = /usr/local/mysql

datadir = /data/mysqldata/3306/data

tmpdir = /data/mysqldata/3306/tmp

open_files_limit = 60000

explicit_defaults_for_timestamp

server-id = 1203306

lower_case_table_names = 1

character-set-server = utf8

federated

#sql_mode=STRICT_TRANS_TABLES

max_connections = 1000

max_connect_errors = 100000

interactive_timeout = 86400

wait_timeout = 86400

sync_binlog=0

back_log=100

default-storage-engine = InnoDB

log_slave_updates = 1

#*********** Logs related settings ***********

log-bin = /data/mysqldata/3306/binlog/mysql-bin

binlog_format= mixed

binlog_cache_size=32m

max_binlog_cache_size=64m

max_binlog_size=512m

long_query_time = 1

log_output = FILE

log-error = /data/mysqldata/3306/mysql-error.log

slow_query_log = 1

slow_query_log_file = /data/mysqldata/3306/slow_statement.log

log_bin_trust_function_creators=1

binlog-format=ROW

#log_queries_not_using_indexes

general_log = 0

general_log_file = /data/mysqldata/3306/general_statement.log

#expire-logs-days = 14

binlog_expire_logs_seconds = 1728000

relay-log = /data/mysqldata/3306/binlog/relay-bin

relay-log-index = /data/mysqldata/3306/binlog/relay-bin.index

#****** MySQL Replication New Feature*********

master-info-repository=TABLE

relay-log-info-repository=TABLE

relay-log-recovery

#*********** INNODB Specific options ***********

innodb_buffer_pool_size = 2048M

transaction-isolation=READ-COMMITTED

innodb_buffer_pool_instances = 8

innodb_file_per_table = 1

innodb_data_home_dir = /data/mysqldata/3306/innodb_ts

innodb_data_file_path = ibdata1:2048M:autoextend

innodb_thread_concurrency = 8

innodb_log_buffer_size = 16M

innodb_log_file_size = 128M

innodb_log_files_in_group = 3

innodb_log_group_home_dir = /data/mysqldata/3306/innodb_log

innodb_flush_log_at_trx_commit = 2

innodb_max_dirty_pages_pct = 70

innodb_flush_method=O_DIRECT

[mysql]

no-auto-rehash

default-character-set=utf8

prompt = (\u@\h) [\d]>\_

#9.初始化MySQL数据库

/usr/local/src/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --initialize --user=mysql

#10.启动mysql服务 mysql用户执行

/usr/local/src/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf --user=mysql &

#11.登陆数据库

备注:密码来自于error log日志,明细如下:

cat /data/mysqldata/3306/mysql-error.log | grep tempo

2018-05-16T07:17:57.335486Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: j

sudo ln -s /data/mysqldata/3306/mysql.sock /tmp/mysql.sock

/usr/local/src/mysql/bin/mysql -uroot -p'VT%0pSTg/eRY'

--eoror:登陆报错(8.0.11不会报错):mysql Segmentation fault (core dumped)

mysql5对应目录:/media/mysql-5.6.38/cmd-line-utils/libedit

在源码包里,编辑文件/media/mysql-5.6.38/cmd-line-utils/libedit/terminal.c (mysql 安装包所在路径)

把terminal_set方法中的 char buf[TC_BUFSIZE]; 这一行注释,实际mysql8.0.12中未注释

再把 area = buf;改为 area = NULL;

cd /usr/local/src/mysql

cmake . \

make

make install

#12.数据库一些基本权限配置

#ALTER USER 'root'@'localhost' IDENTIFIED WITH sha256_password BY 'zsd@7101' PASSWORD EXPIRE INTERVAL 360 DAY;

alter user root@'localhost' identified by 'oracle';

flush privileges;

select host,user,authentication_string from mysql.user;

#root用户赋权和修改密码

update user set host='%' where user='root';

flush privileges;

#默认caching_sh2_passwor密码认证,navicat登陆时:authentication plugin 'caching_sh2_passwor' cannnot be loaded

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'oracle';

grant all privileges on *.* to root@'%';

flush privileges;

--添加到自启动,root用户,服务不能启动,应该mysql用户无权限

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

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --list

chkconfig --level 345 mysqld on

reboot

--或者,添加到root用户,让root可以登录mysql

vi /etc/profile

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

/usr/local/src/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf --user=mysql &

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

mysql中cmake常用参数说明

#允许从本地导入数据

-DENABLED_LOCAL_INFILE=1

#快捷键功能

-DWITH_READLINE=1

-dinstall_includedir:指定头文件的存储路径,默认是保存于cmake_install_prefix/include目录下;

-dinstall_sbindir:指定服务端执行脚本的存储路径,默认是保存于cmake_install_prefix/bin目录下;

-dmysql_unix_addr:指定套接字文件的存储路径,默认是在/tmp/mysql.sock目录下,这一选项可以在MySQL服务启动时通过socket参数进行设置;

-dwith_readline:指定输入输出的处理方式,在5.1及之前版本无需单独处理,默认就是使用readline方式,不过进入5.5版本后,MySQL编译时默认使用libedit处理输入和输出,可能导致当前环境登陆mysql命令行模式后,无法输入中文(仅针对当前编译环境,共他客户端不受影响),因此编译时需要指定其以readline方式处理;

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DCOMPILATION_COMMENT="lq-edition"-DENABLE_DTRACE=1  -DWITH_DEBUG=1

------------------------------------------------------------------------------------------------------------------------------------

--error:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决:

出现次错误时,也可以tcp方式连接mysql:mysql -uroot -poracle

mysql8.0.12用的配置文件为:/data/mysqldata/3306/my.cnf,socket方式连接mysql时会用到/etc/my.cnf

vi /etc/my.cnf 增加

[client]

port=3306

#socket=/var/mysql/mysql.sock

socket=/data/mysqldata/3306/mysql.sock

你可能感兴趣的:(mysql8.0.12源码)