mysql5.6源码安装

时间:2021-02-04 06:15:24

1.环境介绍:

  包:mysql-5.6.24.tar.gz

  平台:centos6.5

2.安装cmake编译工具和依赖包:

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

3.创建mysql用户:

useradd mysql -s /sbin/nologin

4.安装编译mysql

  a.进入mysql安装目录

  b.cmake编译:

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EMBEDDED_SERVER=1 -DWITH_SSL=system

  参数说明:

    -DCMAKE_INSTALL_PREFIX:指定mysql主目录

-DMYSQL_DATADIR:指定数据文件存放位置

-DSYSCONFDIR:指定my.cnf路径

-DMYSQL_UNIX_ADDR:指定连接数据库socket文件路径

  -DENABLED_LOCAL_INFILE=1:允许从本地导入数据

  -DEXTRA_CHARSETS=all:安装所有的字符集

   -DDEFAULT_CHARSET=utf8:指定默认字符

  -DWITH_PARTITION_STORAGE_ENGINE=1:安装支持数据库分区

  c.gmake

  d.make install

e.如果报错

make[]: *** [libmysqld/examples/mysql_client_test_embedded] 错误
make[]: *** [libmysqld/examples/CMakeFiles/mysql_client_test_embedded.dir/all] 错误

解决:加上如下

-DWITH_EMBEDDED_SERVER=OFF

5.cp相关文件和修改参数:

  a.拷贝

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

  b.修改参数(创建目录:mkdir /var/lib/mysql):

[client]
port =
socket = /tmp/mysqld.sock [mysql]
no-auto-rehash [mysqld]
user = mysql
port =
socket = /tmp/mysqld.sock
basedir = /usr/local/mysql
datadir = /var/lib/mysql
open_files_limit=

character-set-server = utf8 back_log =
max_connections =
max_connect_errors =
table_open_cache =
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size =
thread_concurrency =
query_cache_size = 64M
query_cache_limit = 4M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M slow-query-log=
slow_query_log_file=/usr/local/mysql/slow-log.log
long_query_time= log-bin
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 512M expire_logs_days =
key_buffer_size = 2048M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads =
myisam_recover
skip-name-resolve
lower_case_table_names = [mysqldump]
quick
max_allowed_packet = 32M [mysqld_safe]
log-error=/usr/local/mysql/mysql.err
pid-file=/usr/local/mysql/mysqld.pid

6.修改环境变量:

vim .bash_profile

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

7.运行mysql_install_db文件:

./mysql_install_db --basedir=/usr/local/mysql --datadir=/var/lib/mysql --no-default --user=mysql

centos7初始化报错:

FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper

解决:

先用list 查找下module:

#yum list|grep -i perl-modul*
perl-Module-Build.noarch :0.40.-.el7 base
perl-Module-CoreList.noarch :2.76.-.el7 base
perl-Module-Implementation.noarch 0.06-.el7 base
perl-Module-Install.noarch 1.06-.el7 base
perl-Module-Load.noarch :0.24-.el7 base
perl-Module-Load-Conditional.noarch 0.54-2.0..el7.centos base
perl-Module-Loaded.noarch :0.08-.el7 base
perl-Module-Manifest.noarch 1.08-.el7 base
perl-Module-Metadata.noarch 1.000018-.el7 base
perl-Module-Pluggable.noarch :4.8-.el7 base
perl-Module-Runtime.noarch 0.013-.el7 base
perl-Module-ScanDeps.noarch 1.10-.el7 base
perl-Module-Signature.noarch 0.73-.el7 base

安装 perl-module:

yum install -y perl-Module-Install.noarch

再次报错:

Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.: cannot open shared object file: No such file or directory

解决方法:安装 libaio

yum install -y libaio libaio-devel

8.启动mysql服务:

service mysql start

9.查看mysql进程:

ps –ef|grep mysql