mysql5.7源码安装

发布时间:2020-09-27 04:27:52 作者:ting2junshui
来源:网络 阅读:1321
安装依赖包
  1. yum -y install gcc gcc-c++ ncurses ncurses-devel cmake

下载相应源码包
  1. cd /root/oneinstack/src

  2. wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

  3. wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz

添加mysql用户
  1. useradd -M -s /sbin/nologin mysql

预编译
  1. tar xzf boost_1_59_0.tar.gz

  2. tar xzf mysql-5.7.11.tar.gz

  3. mkdir -p /data/mysql

  4. cd mysql-5.7.11

  5. cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

  6. -DMYSQL_DATADIR=/data/mysql \

  7. -DDOWNLOAD_BOOST=1 \   #从MySQL 5.7.5开始Boost库是必需的

  8. -DWITH_BOOST=../boost_1_59_0 \

  9. -DSYSCONFDIR=/etc \

  10. -DWITH_INNOBASE_STORAGE_ENGINE=1 \

  11. -DWITH_PARTITION_STORAGE_ENGINE=1 \

  12. -DWITH_FEDERATED_STORAGE_ENGINE=1 \

  13. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

  14. -DWITH_MYISAM_STORAGE_ENGINE=1 \

  15. -DENABLED_LOCAL_INFILE=1 \

  16. -DENABLE_DTRACE=0 \

  17. -DDEFAULT_CHARSET=utf8mb4 \

  18. -DDEFAULT_COLLATION=utf8mb4_general_ci \

  19. -DWITH_EMBEDDED_SERVER=1


cmake . -DCMAKE_INSTALL_PREFIX=/srv/mysql5713 \

-DMYSQL_DATADIR=/srv/mysql5713/data \

-DMYSQL_UNIX_ADDR=/srv/mysql5713/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATER_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_EXAMPLE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_FAST_MUTEXES=1 \

-DWITH_ZLIB=bundled \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_READLINE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DWITH_DEBUG=0 \

-DWITH_BOOST=/srv/mysql/boost_1_59_0



编译安装

   make

   make install

启动脚本,设置开机自启动
  1. /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

  2. chmod +x /etc/init.d/mysqld

  3. chkconfig --add mysqld

  4. chkconfig mysqld on


/etc/my.cnf,仅供参考
  1. vim /etc/my.cnf

  2. [client]

  3. port = 3306

  4. socket = /tmp/mysql.sock

  5. default-character-set = utf8mb4


  6. [mysqld]

  7. port = 3306

  8. socket = /tmp/mysql.sock


  9. basedir = /usr/local/mysql

  10. datadir = /data/mysql

  11. pid-file = /data/mysql/mysql.pid

  12. user = mysql

  13. bind-address = 0.0.0.0

  14. server-id = 1


  15. init-connect = 'SET NAMES utf8mb4'

  16. character-set-server = utf8mb4


  17. #skip-name-resolve

  18. #skip-networking

  19. back_log = 300


  20. max_connections = 1000

  21. max_connect_errors = 6000

  22. open_files_limit = 65535

  23. table_open_cache = 128

  24. max_allowed_packet = 4M

  25. binlog_cache_size = 1M

  26. max_heap_table_size = 8M

  27. tmp_table_size = 16M


  28. read_buffer_size = 2M

  29. read_rnd_buffer_size = 8M

  30. sort_buffer_size = 8M

  31. join_buffer_size = 8M

  32. key_buffer_size = 4M


  33. thread_cache_size = 8


  34. query_cache_type = 1

  35. query_cache_size = 8M

  36. query_cache_limit = 2M


  37. ft_min_word_len = 4


  38. log_bin = mysql-bin

  39. binlog_format = mixed

  40. expire_logs_days = 30


  41. log_error = /data/mysql/mysql-error.log

  42. slow_query_log = 1

  43. long_query_time = 1

  44. slow_query_log_file = /data/mysql/mysql-slow.log


  45. performance_schema = 0

  46. explicit_defaults_for_timestamp


  47. #lower_case_table_names = 1


  48. skip-external-locking


  49. default_storage_engine = InnoDB

  50. #default-storage-engine = MyISAM

  51. innodb_file_per_table = 1

  52. innodb_open_files = 500

  53. innodb_buffer_pool_size = 64M

  54. innodb_write_io_threads = 4

  55. innodb_read_io_threads = 4

  56. innodb_thread_concurrency = 0

  57. innodb_purge_threads = 1

  58. innodb_flush_log_at_trx_commit = 2

  59. innodb_log_buffer_size = 2M

  60. innodb_log_file_size = 32M

  61. innodb_log_files_in_group = 3

  62. innodb_max_dirty_pages_pct = 90

  63. innodb_lock_wait_timeout = 120


  64. bulk_insert_buffer_size = 8M

  65. myisam_sort_buffer_size = 8M

  66. myisam_max_sort_file_size = 10G

  67. myisam_repair_threads = 1


  68. interactive_timeout = 28800

  69. wait_timeout = 28800


  70. [mysqldump]

  71. quick

  72. max_allowed_packet = 16M


  73. [myisamchk]

  74. key_buffer_size = 8M

  75. sort_buffer_size = 8M

  76. read_buffer = 4M

  77. write_buffer = 4M

  78. EOF

初始化数据库
  1. 之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃

  2. "--initialize"会生成一个随机密码(~/.mysql_secret),而"--initialize-insecure"不会生成密码

  3. --datadir目标目录下不能有数据文件


  4. /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql



启动数据库

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

  service mysql start

 chkconfig mysql on




设置数据库密码
  1. dbrootpwd=oneinstack  #数据库root密码

  2. /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"

  3. /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"

  4. 新版的mysql数据库下的user表中已经没有Password字段了,而是将加密后的用户密码存储于authentication_string字段 





安装

1> 添加mysql用户

shell> cd /opt/mysql-server
shell> groupadd mysql #添加mysql用户组
shell> useradd -r -g mysql -s /bin/false mysql #添加mysql用户

2> 配置mysql预编译参数

shell> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all


更多预编译配置参数请参考mysql官方文档说明:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#cmake-general-options

3> 编译并安装

shell> make -j `grep processor /proc/cpuinfo | wc -l`shell> make install

-j参数表示根据CPU核数指定编译时的线程数,可以加快编译速度。默认为1个线程编译,经测试单核CPU,1G的内存,编译完需要将近1个小时。

4> 初始化系统数据库

shell> cd /usr/local/mysql
shell> chown -R mysql:mysql .
# 注意:MySQL 5.7.6之前的版本执行这个脚本初始化系统数据库
shell> ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 5.7.6之后版本初始系统数据库脚本(本文使用此方式初始化)
shell> ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
shell> ./bin/mysql_ssl_rsa_setup
shell> chown -R root .
shell> chown -R mysql data


5、设置配置文件

shell> cp support-files/my-default.cnf /etc/my.cnf

6、配置mysql服务

shell> cp support-files/mysql.server /etc/init.d/mysqld
shell> chkconfig --add mysqld     # 添加到系统服务
shell> chkconfig mysqld on        # 开机启动

7、启动服务

shell> service mysqld start       # 启动mysql服务
shell> service mysqld stop        # 停止mysql服务
shell> service mysqld restart     # 重新启动mysql服务

8、设置数据库密码

shell> /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by "root" with grant option;"
shell> /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by "root" with grant option;"# 开启远程登录(将host设为%即可)/usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'%' identified by "root" with grant option;"

9、配置mysql环境变量

shell> vim /etc/profile
shell> export PATH=/usr/local/mysql/bin:$PATH
shell> source /etc/profile

其它注意事项

如果中途编译失败了,需要删除cmake生成的预编译配置参数的缓存文件和make编译后生成的文件,再重新编译。

shell> cd /opt/mysql-server
shell> rm -f CMakeCache.txt
shell> make clean












推荐阅读:
  1. centos7源码安装mysql5.7的过程
  2. 源码安装php

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql5.7 码安装 mysql5.

上一篇:Spring MVC+FastJson+hibernate-validator整合的完整实例教程

下一篇:C# XML操作类分享

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》