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 

预编译: 

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


编译安装: 
    make && make install 

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

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

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

Xml代码   收藏代码
  1. #dvice on how to change settings please see  
  2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html  
  3. # # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the  
  4. # # *** default location during install, and will be replaced if you  
  5. # # *** upgrade to a newer version of MySQL.  
  6.   
  7.   
  8. [client]  
  9. port=3306  
  10. socket=/data/mysql/config/mysql.sock  
  11.   
  12. [mysqld]  
  13.   
  14. # Remove leading # and set to the amount of RAM for the most important data  
  15. # # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.  
  16. # # innodb_buffer_pool_size = 128M  
  17. #  
  18. # # Remove leading # to turn on a very important data integrity option: logging  
  19. # # changes to the binary log between backups.  
  20. # # log_bin  
  21. #  
  22. # # These are commonly set, remove the # and set as required.  
  23.   
  24.   
  25. #skip-grant-tables  
  26. #skip-networking  
  27.   
  28. user = mysql  
  29. basedir = /opt/mysql  
  30. datadir = /data/mysql/data  
  31. port=3306  
  32. server-id = 1  
  33. socket=/data/mysql/config/mysql.sock  
  34.   
  35. character-set-server = utf8  
  36. log-error = /var/log/mysql/error.log  
  37. pid-file = /var/log/mysql/mysql.pid  
  38. general_log = 1  
  39. skip-name-resolve  
  40. #skip-networking  
  41. back_log = 300  
  42.   
  43. max_connections = 1000  
  44. max_connect_errors = 6000  
  45. open_files_limit = 65535  
  46. table_open_cache = 128   
  47. max_allowed_packet = 4M  
  48. binlog_cache_size = 1M  
  49. max_heap_table_size = 8M  
  50. tmp_table_size = 16M  
  51.   
  52. read_buffer_size = 2M  
  53. read_rnd_buffer_size = 8M  
  54. sort_buffer_size = 8M  
  55. join_buffer_size = 28M  
  56. key_buffer_size = 4M  
  57.   
  58. thread_cache_size = 8  
  59.   
  60. query_cache_type = 1  
  61. query_cache_size = 8M  
  62. query_cache_limit = 2M  
  63.   
  64. ft_min_word_len = 4  
  65.   
  66. log_bin = mysql-bin  
  67. binlog_format = mixed  
  68. expire_logs_days = 30  
  69.   
  70. performance_schema = 0  
  71. explicit_defaults_for_timestamp  
  72.   
  73. #lower_case_table_names = 1  
  74.   
  75. myisam_sort_buffer_size = 8M  
  76. myisam_repair_threads = 1  
  77.   
  78. interactive_timeout = 28800  
  79. wait_timeout = 28800  
  80.   
  81. # Remove leading # to set options mainly useful for reporting servers.  
  82. # # The server defaults are faster for transactions and fast SELECTs.  
  83. # # Adjust sizes as needed, experiment to find the optimal values.  
  84. # # join_buffer_size = 128M  
  85. # # sort_buffer_size = 2M  
  86. # # read_rnd_buffer_size = 2M   
  87. #  
  88. # # Disabling symbolic-links is recommended to prevent assorted security risks  
  89.   
  90. symbolic-links=0  
  91.   
  92. # Recommended in standard MySQL setup  
  93.   
  94. sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES   
  95.   
  96. [mysqldump]  
  97. quick  
  98. max_allowed_packet = 16M  
  99.   
  100. [myisamchk]  
  101. key_buffer_size = 8M  
  102. sort_buffer_size = 8M  
  103. read_buffer = 4M  
  104. write_buffer = 4M  


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

Xml代码   收藏代码
  1. 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; 


转自:http://smallbug-vip.iteye.com/blog/2275002

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值