鲲鹏凌云上源码安装MySQL5.7.28

参考链接:https://bbs.huaweicloud.com/forum/thread-47298-1-1.html

由于该链接有n多个坑,所以迫于无奈,自己又总结了一下:

1.环境:centos7.5     8核16G  鲲鹏凌云服务器

2.安装依赖包
执行以下命令安装依赖包:
yum install bison* ncurses* -y
yum install bzip2 wget openssl-devel -y
3.配置MySQL编译环境
检查cmake是否安装。
rpm -qa |grep cmake
如果未安装,需要安装。。
cd /home
wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz
tar -zxvf cmake-3.9.2.tar.gz
cd cmake-3.9.2
./configure
make && make install
cmake -version

 

 4.升级gcc版本至7.3.0    编译安装gcc的时间将会特别长!!!
cd /home
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
tar -xvf gcc-7.3.0.tar.gz
cd /home/gcc-7.3.0
将安装包下载放置于“/home/gcc-7.3.0”目录下,如下载比较慢有条件可通过香港去主机下载过来。
wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
在“gcc-7.3.0”目录下,检查gcc的依赖包是否已下载和安装。
./contrib/download_prerequisites

 

 编译安装gcc,“-j”参数可利用多核CPU加快编译速度,在本示例中,使用的是16核CPU,所以此处为“-j16”。
可通过下述命令查询CPU核数:
cat /proc/cpuinfo| grep "processor"| wc -l
cd /home/gcc-7.3.0
mkdir gcc-build-7.3.0
cd gcc-build-7.3.0
../configure --enable-checking=release --enable-language=c,c++ --disable-multilib --prefix=/usr
make -j16
make install
确定“libstdc++.so、libstdc++.so.6.0.24”是在“/usr/lib64”目录下。
cd /usr/lib64
ll |grep libstdc++.so
ll |grep libstdc++.so.6.0.24
查看gcc版本
gcc -v

 

5.MySQL安装
下载源码
cd /home/
wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.28.tar.gz
解压
tar -zvxf mysql-boost-5.7.28.tar.gz
cd /home/mysql-5.7.28
配置参数,以下是整条命令不要换行
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/home/mysql-5.7.28/boost/boost_1_59_0
6.Bug处理,在文件首行添加即可,不然会编译失败

在解压后的目录下,编辑该文件,在首行加上一下内容即可

vim /home/mysql-5.7.28/sql/mysqld.cc

  #include <sys/prctl.h>

  .........

若在预编译时出现依赖包不全的情况,可自行查阅资料安装依赖包,并重新预编译。
重新预编译前,需要执行rm -f CMakeCache.txt。
make -j16
make install

7.配置MySQL
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql
mkdir -p /data/log /data/data /data/run

8.初始化操作,执行下述命令后,会产生初始随机密码,需要记录。
bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/data --user=mysql

chown -R mysql:mysql /data
ln -s /data/data/mysql.sock /tmp/mysql.sock

9.配置/etc/my.cnf文件

cat > /etc/my.cnf<<EOF
[client]
#password   = your_password
port        = 3306
socket      = /data/data/mysql.sock
[mysqld]
port        = 3306
socket      = /data/data/mysql.sock
datadir = /data/data
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
performance_schema_max_table_instances = 500
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
expire_logs_days = 10
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /data/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/data
innodb_buffer_pool_size = 16M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 8
innodb_write_io_threads = 8
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer_size = 2M
write_buffer_size = 2M
[mysqlhotcopy]
interactive-timeout
EOF

10.服务配置
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start
11.环境配置
vim ~/.bash_profile
export PATH=/usr/local/mysql/bin:$PATH
source ~/.bash_profile
12.登录修改密码
mysql -uroot -p"密码"
alter user 'root'@'localhost' identified by 'HuaWei#231';
mysql -uroot -pHWjob#231

posted @ 2020-05-05 17:41  New_Journey  阅读(528)  评论(0编辑  收藏  举报