首页 > Mysql > centos7编译安装MySQL5.7.25

centos7编译安装MySQL5.7.25

1 下载mysql源码包
在mysql网站,左边选MySql Community Server,选带boost的版本
“Select Version”选版本,Select Platform选”Source Code”,然后选”Generic Linux”

2、安装依赖
(1)下载和解压boost,需要fanqiang
下载链接:https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
上传到机器上,我的目录是/usr/local/src目录,然后解压
(2)其它依赖

yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison

3、建mysql用户
使用useradd建msyql用户,变改其口令

4、解压编译mysql,用root用户
我同样是放在了/usr/local/src目录
预编译命令

cd /usr/local/src/mysql-5.7.25

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-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 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/src/boost_1_59_0

编译安装,过程很漫长,阿里云1C,1G的编译会报错,原因基本为内存不足。可以使用临时使用交换分区来解决

[root@gxdam mysql-5.7.25]# dd if=/dev/zero of=/swapfile bs=64M count=16
[root@gxdam mysql-5.7.25]# mkswap /swapfile
[root@gxdam mysql-5.7.25]# swapon /swapfile
[root@gxdam mysql-5.7.25]# swapon -s

完成后继续上面 make 命令

然后:

make && make install

5 设置开机启动,root用户

cp /mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/sbin/chkconfig mysqld on

6 修改mysql配置文件

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
user=mysql
sql_mode=”ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”
innodb_buffer_pool_size = 256M
innodb_large_prefix = ON
innodb_file_format = Barracuda
innodb_file_per_table = ON
basedir = /mysql
datadir = /mysql/data
port = 3306
server_id = 1
socket = /tmp/mysql.sock
character_set_server=utf8
sort_buffer_size = 16M
read_rnd_buffer_size = 16M
log-error=/mysql/log/mysql.log
pid-file=/mysql/run/mysql.pid
#bind-address = 0.0.0.0
max_connections = 1000
slow_query_log_file = /mysql/log/slow.log
default_storage_engine = InnoDB

[mysqld_safe]
log-error=/mysql/log/mysql.log
pid-file=/mysql/run/mysql.pid

[mysqldump]
quick

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

7 安装收尾工作
(1)把/mysql/bin加入mysql用户的PATH变量中
(2)修改/mysql的权限给mysql用户,用root执行

chown -R mysql:mysql /mysql

8 初始化数据库

[root@gxdam bin]# ./mysql_install_db –verbose –user=mysql –basedir=/mysql –datadir=/mysql/data

9 启动数据库

[root@gxdam bin]# systemctl start mysqld
[root@gxdam bin]# systemctl status mysqld

10 设置数据库root用户密码

[root@gxdam bin]# ./mysql_secure_installation

按自己想要的yes或no就可以了

11 把mysql加入到系统共享库

[root@gxdam bin]# echo “/mysql/lib” > /etc/ld.so.conf.d/mysql.conf
[root@gxdam bin]# ldconfig -v | grep mysql
/usr/lib64/mysql:
libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
/mysql/lib:
libmysqlclient.so.20 -> libmysqlclient.so.20.3.12

12 用root连上试一下
若提示:You must reset your password using ALTER USER statement before executing,则如下操作:

SET PASSWORD = PASSWORD(‘your password’);
ALTER USER ‘root’@’localhost’ PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;

再试:

[mysql@gxdam ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.25 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| sys |
+——————–+
4 rows in set (0.00 sec)

mysql>

分类: Mysql 标签: , , , ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.