`

CentOS7编译安装MySQL5.7.10

阅读更多
      之前一直用rpm格式安装包来安装MySQL。但是在打rpm包之前很多参数都被设置好了,用起来很不方便,或者说很不舒服。再者就是网上的教程多半都是比较早的,有很多细节已经过时了,所以决定自己亲自动手在最新版的CentOS7上编译安装最新版的MySQL5.7.10.

os:Linux mysql01 3.10.0-229.el7.i686 #1 SMP Sun May 17 14:06:40 UTC 2015 i686 i686 i386 GNU/Linux
database:mysql  Ver 14.14 Distrib 5.7.10, for Linux (i686) using  EditLine wrapper

准备的源码包:
      mysql-5.7.10.tar.gz(下载链接:http://120.52.72.46/cdn.mysql.com/c3pr90ntcsf0//Downloads/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-i686.tar.gz

      boost_1_59_0.tar.gz(下载链接:http://vorboss.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz


工具安装:yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

创建用户组:
   groupadd mysql

创建mysql用户:
    useradd -r -g mysql -s /bin/mysql_shell -M mysql

创建/opt/mysql文件夹:
    mkdir /opt/mysql

创建/data/mysql/data:
    mkdir -p /data/mysql/data

创建/data/mysql/config
    mkdir -p /data/mysql/config

修改文件的所有者为mysql所属组为mysql:
   chown mysql:mysql /opt/mysql
   chown -R mysql:mysql /data

创建/opt/boost文件夹
   mkdir /opt/boost

将boost_1_59_0.tar.gz解压放到/opt/boost文件夹中
  tar zxvf boost_1_59_0.tar.gz

预编译:
cmake . \
-DCMAKE_INSTALL_PREFIX=/opt/mysql  \					 [MySQL安装的根目录]
-DMYSQL_DATADIR=/data/mysql/data  \						 [MySQL数据库文件存放目录]
-DSYSCONFDIR=/etc \										 [MySQL配置文件所在目录]
-DMYSQL_USER=mysql \									 [MySQL用户名]  
-DWITH_MYISAM_STORAGE_ENGINE=1 \						 [MySQL的数据库引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 \						 [MySQL的数据库引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \						 [MySQL的数据库引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 \						 [MySQL的数据库引擎]
-DWITH_READLINE=1 \										 [MySQL的readline library]
-DMYSQL_UNIX_ADDR=/data/mysql/config/mysql.sock \		 [MySQL的通讯目录]
-DMYSQL_TCP_PORT=3306 \									 [MySQL的监听端口]
-DENABLED_LOCAL_INFILE=1 \								 [启用加载本地数据]
-DENABLE_DOWNLOADS=1 \									 [编译时允许自主下载相关文件]
-DWITH_PARTITION_STORAGE_ENGINE=1  \
-DEXTRA_CHARSETS=all \									 [使MySQL支持所有的扩展字符]
-DDEFAULT_CHARSET=utf8 \								 [设置默认字符集为utf8]
-DDEFAULT_COLLATION=utf8_general_ci \					 [设置默认字符校对]
-DWITH_DEBUG=0 \										 [禁用调试模式]
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \								 [通讯时支持ssl协议]
-DWITH_ZLIB:STRING=bundled \							 [允许使用zlib library]
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/opt/boost


编译安装:
    make && make install

这段时间很长,要有心理准备哦。。。。。。。。

使用命令查看MySQL的安装目录/opt/mysql/下面是否生成了相关目录文件(最重要的当然是bin和lib目录)。如果lib目录下面没有生成如图所示的.so动态库文件和.a静态库文件,那么说明安装不成功(即使成功了也可能会导致php进程无法找到mysql的相关库文件)。

修改/etc/my.cnf配置文件:

#dvice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# # *** default location during install, and will be replaced if you
# # *** upgrade to a newer version of MySQL.


[client]
port=3306
socket=/data/mysql/config/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# # innodb_buffer_pool_size = 128M
#
# # Remove leading # to turn on a very important data integrity option: logging
# # changes to the binary log between backups.
# # log_bin
#
# # These are commonly set, remove the # and set as required.


#skip-grant-tables
#skip-networking

user = mysql
basedir = /opt/mysql
datadir = /data/mysql/data
port=3306
server-id = 1
socket=/data/mysql/config/mysql.sock

character-set-server = utf8
log-error = /var/log/mysql/error.log
pid-file = /var/log/mysql/mysql.pid
general_log = 1
skip-name-resolve
#skip-networking
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128 
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30

performance_schema = 0
explicit_defaults_for_timestamp

#lower_case_table_names = 1

myisam_sort_buffer_size = 8M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800

# Remove leading # to set options mainly useful for reporting servers.
# # The server defaults are faster for transactions and fast SELECTs.
# # Adjust sizes as needed, experiment to find the optimal values.
# # join_buffer_size = 128M
# # sort_buffer_size = 2M
# # read_rnd_buffer_size = 2M 
#
# # Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Recommended in standard MySQL setup

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES 

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M


将mysql命令加入PATH中:
修改/etc/profile文件,在最后添加:

export PATH=/opt/mysql/bin:$PATH


创建存放日志文件夹:
    mkdir -p /var/log/mysql

初始化MySQL自身的数据库:
mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/data/mysql/data

设置开机启动:
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld #增加可执行权限
chkconfig --add mysqld #添加到sysV服务
chkconfig mysqld on

启动MySQL服务:
    mysqld_safe --user=mysql --datadir=/data/mysql/data --log-error=/var/log/mysql/error.log

修改root密码:

执行:
mysqld_safe --skip-grant-tables &
另起客户端mysql -u root -p【回车】
【回车】

进入SQL状态:
SQL>use mysql;
SQL>update mysql.user set authentication_string=password('smallbug') where user='root' and Host = 'localhost';

重启MySQL:
    /etc/init.d/mysqld restart

设置远程登录:
   update user set host='%' where user='root';
   flush privileges;


2
0
分享到:
评论
1 楼 hottymg 2016-02-02  
 

相关推荐

Global site tag (gtag.js) - Google Analytics