源编译mysql-5.1.65

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 添加用户和用户组 点击(此处)折叠或打开groupadd mysql useradd -g mysql mysql解压mysql文件&0编译源代码 点击(此处)折叠或打开tar zxvf mysql-5.
添加用户和用户组

点击(此处)折叠或打开

  1. groupadd mysql

  2. useradd -g mysql mysql

解压mysql文件&0编译源代码

点击(此处)折叠或打开

  1. tar zxvf mysql-5.1.65.tar.gz

  2. cd mysql-5.1.65


  3. ./configure --prefix=/usr/local/mysql/ --with-server-suffix=-zsd-edition --enable-assembler --enable-local-infile --enable-thread-safe-client --with-big-tables --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8,ascii --with-readline --with-ssl --with-embedded-server --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-plugins=partition,innobase,innodb_plugin > /root/mysql_setuplogs_configure.log 2>&1

查看/root/mysql_setuplogs_configure.log,如果出现libtool的问题,按下述方法可解决

查看libtool是否已经安装。

1、确认libtool是否已经安装,如果没有安装的话,则先安装libtool

点击(此处)折叠或打开

  1. # rpm -qa | grep libtool

  2. # yum -y install libtool
2、分别执行以下三条命令:

点击(此处)折叠或打开

  1. # autoreconf --force --install

  2. # libtoolize --automake --force

  3. # automake --force --add-missing

make&安装:

点击(此处)折叠或打开

  1. make > /root/mysql_setuplogs_make.log 2>&1

  2. make install > /root/mysql_setuplogs_makeinstall.log 2>&1

修改相关路径权限:

点击(此处)折叠或打开

  1. cd /usr/local/

  2. chown -R mysql:mysql mysql

  3. mkdir -p /data/mysqldata/3306
  4. cd /data/mysqldata/3306
  5. mkdir data binlog tmp innodb_ts innodb_log

  6. chown -R mysql:mysql ./
创建mysql_install_db

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata/3306/data

配置my.cnf


点击(此处)折叠或打开

  1. vi /data/mysqldata/3306/my.cnf



  2. [client]
  3. port = 3306
  4. socket = /data/mysqldata/3306/mysql.sock
  5. character-set-server = utf8

  6. # Here follows entries for some specific programs

  7. # The MySQL server
  8. [mysqld]
  9. port = 3306
  10. user = mysql
  11. socket = /data/mysqldata/3306/mysql.sock
  12. pid-file = /data/mysqldata/3306/mysql.pid
  13. basedir = /usr/local/mysql
  14. datadir = /data/mysqldata/3306/data
  15. tmpdir = /data/mysqldata/3306/tmp
  16. open_files_limit = 10240
  17. server-id = 1333306
  18. lower_case_table_names = 1
  19. character-set-server = utf8
  20. skip-name-resolve

  21. max_connections = 3000
  22. max_connect_errors = 6000
  23. max_allowed_packet = 512M
  24. max_heap_table_size = 1024M
  25. max_length_for_sort_data = 4096
  26. back_log=100
  27. interactive_timeout = 600
  28. wait_timeout = 600

  29. default-storage-engine = InnoDB

  30. net_buffer_length = 8K
  31. sort_buffer_size = 2M
  32. join_buffer_size = 4M
  33. read_buffer_size = 2M
  34. read_rnd_buffer_size = 16M

  35. query_cache_size = 128M
  36. query_cache_limit = 2M
  37. query_cache_min_res_unit = 2k

  38. thread_cache_size = 300
  39. table_open_cache = 1024
  40. tmp_table_size = 256M

  41. #*********** Logs related settings ***********
  42. log-bin = /data/mysqldata/3306/binlog/mysql-bin
  43. log-slave-updates =1
  44. binlog_format=statement
  45. binlog_cache_size=32m
  46. max_binlog_cache_size=512m
  47. max_binlog_size=512m
  48. long_query_time = 3
  49. log_output = FILE
  50. log-error = /data/mysqldata/3306/mysql-error.log
  51. slow_query_log = 1
  52. slow_query_log_file = /data/mysqldata/3306/slow_statement.log
  53. log_queries_not_using_indexes
  54. general_log = 0
  55. general_log_file = /data/mysqldata/3306/general_statement.log
  56. expire-logs-days = 14

  57. #*********** MyISAM Specific options ***********
  58. key_buffer_size = 32M
  59. bulk_insert_buffer_size = 64M
  60. myisam_sort_buffer_size = 128M
  61. myisam_max_sort_file_size = 10G
  62. myisam_repair_threads = 1
  63. myisam_recover

  64. #*********** INNODB Specific options ***********
  65. innodb_file_per_table
  66. transaction-isolation = READ-COMMITTED

  67. innodb_additional_mem_pool_size = 16M
  68. innodb_buffer_pool_size = 1024M
  69. innodb_data_home_dir = /data/mysqldata/3306/innodb_ts
  70. innodb_data_file_path = ibdata1:2048M:autoextend

  71. innodb_file_io_threads = 4
  72. innodb_thread_concurrency = 0
  73. innodb_log_buffer_size = 16M
  74. innodb_log_file_size = 256M
  75. innodb_log_files_in_group = 2

  76. innodb_log_group_home_dir = /data/mysqldata/3306/innodb_log
  77. innodb_flush_log_at_trx_commit = 2
  78. innodb_max_dirty_pages_pct = 80
  79. innodb_lock_wait_timeout = 120
  80. innodb_flush_method=O_DIRECT

  81. [mysqldump]
  82. quick
  83. max_allowed_packet = 512M

  84. [mysql]
  85. no-auto-rehash
  86. # Remove the next comment character if you are not familiar with SQL
  87. #safe-updates

  88. [myisamchk]
  89. key_buffer_size = 32M
  90. sort_buffer_size = 20M
  91. read_buffer_size = 2M
  92. write_buffer_size = 2M

  93. [mysqlhotcopy]
  94. interactive-timeout

  95. [mysqld_safe]
  96. open-files-limit = 8192

启动mysql服务:

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &

进入mysql:

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysql -uroot -S /data/mysqldata/3306/mysql.sock

关闭mysql:

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysqladmin -uroot -S /data/mysqldata/3306/mysql.sock shutdown

安装mysql后,对安全性做一点设置:

(1)删除掉不安全的用户:

点击(此处)折叠或打开

  1. drop user ''@'localhost';
  2. drop user ''@'mysql-n1';

(2)为root用户设置密码:(以root用户登录)

点击(此处)折叠或打开

  1. set password=password('zsd0507');

设置环境变量:

点击(此处)折叠或打开

  1. sudo su - mysql

  2. vi /home/mysql/.bash_profile

  3. umask 022

  4. MYSQL_BASE=/usr/local/mysql
  5. MYSQL_HOME=/usr/local/mysql

  6. PATH=$MYSQL_BASE/bin:$PATH

  7. export PATH
  8. export MYSQL_BASE MYSQL_HOME

  9. 使得环境变量生效:

  10. source /home/mysql/.bash_profile

设置启动脚本(让它跟系统一起自动启动)


点击(此处)折叠或打开

  1. cd /etc/init.d

  2. vi mysql

#!/bin/sh

mysql_port=3306
mysql_username="root"
mysql_password="zsd0507"

function_start_mysql()
{
    printf "Starting MySQL...\n"
    /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/

${mysql_port}/my.cnf 2>&1 > /dev/null &
}

function_stop_mysql()
{
    printf "Stoping MySQL...\n"
    /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S

/data/mysqldata/${mysql_port}/mysql.sock shutdown
}

function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    function_stop_mysql
    sleep 5
    function_start_mysql
}

function_kill_mysql()
{
    kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf

$2}')
    kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf

$2}')
}

if [ "$1" = "start" ]; then
    function_start_mysql
elif [ "$1" = "stop" ]; then
    function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
    printf "Usage: /data/mysqldata/${mysql_port}/mysql {start|stop|restart|

kill}\n"
fi

  1. chmod 755 mysql

到此,全部结束!~



相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
6月前
|
监控 关系型数据库 MySQL
MySQL全面解析:安装与设置详细指南
【1月更文挑战第1天】,MySQL是一款开源的关系型数据库管理系统,被广泛应用于Web应用程序的开发中。本文将深入探讨MySQL的概念、特性,以及详细介绍MySQL的安装和设置过程,帮助你快速搭建一个强大的数据库环境。
587 0
MySQL全面解析:安装与设置详细指南
|
Java 数据库连接
MySQL5版本的配置改成MySQL8
MySQL5版本的配置改成MySQL8
193 0
MySQL5版本的配置改成MySQL8
|
关系型数据库 MySQL Java
Centos7安装jdk8以及mysql5.7以及Navicat连接虚拟机mysql的出错以及解决方法(附mysql下载出错解决办法)
Centos7安装jdk8以及mysql5.7以及Navicat连接虚拟机mysql的出错以及解决方法(附mysql下载出错解决办法)
220 0
|
关系型数据库 MySQL Linux
MySQL的各种安装方式都给你(下)
MySQL的各种安装方式都给你(下)
210 0
MySQL的各种安装方式都给你(下)
|
关系型数据库 MySQL Linux
Linux安装MySQL时注意事项
主要针对遇到的异常进行记录,后续遇到会继续填充
|
关系型数据库 MySQL Linux
MySQL的各种安装方式都给你(上)
MySQL的各种安装方式都给你(上)
249 0
MySQL的各种安装方式都给你(上)
|
关系型数据库 MySQL Java
MySQL的下载、配置
MySQL的下载、配置
1124 0
MySQL的下载、配置
|
关系型数据库 MySQL 数据库
mysql三种安装方式
mysql三种安装方式
125 0
|
Kubernetes 关系型数据库 MySQL