[关闭]
@Great-Chinese 2016-10-12T16:03:02.000000Z 字数 2171 阅读 822

源码编译安装 Mysql5.5

Mysql


1.1下载源码

http://mirrors.sohu.com/mysql/ 现在需要的Mysql版本 例如: mysql-5.5.51.tar.gz

1.2安装编译相关软件

  1. yum install -y cmake ncurses-devel gcc gcc-c++ ncurses libaio bison

1.2创建数据目录和Mysql运行账号

  1. mkdir /data/mysql
  2. groupadd mysql
  3. useradd -g mysql mysql

1.3解压下载目录

  1. tar -xvf mysql-5.5.51.tar.gz

1.4 make 编译

  1. time cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5 -DMYSQL_DATADIR=/data/mysql5 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR==/usr/local/mysql5/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_C
  2. # 编译安装
  3. make && make install

1.5修改配置文件my.cnf

  1. [client]
  2. port = 3311
  3. socket = /data/mysql5/mysql.sock
  4. # The MySQL server
  5. [mysqld]
  6. datadir = /data/mysql5
  7. port = 3311
  8. socket = /data/mysql5/mysql.socket
  9. # 设置分配给数据库内存的50-70%
  10. innodb_buffer_pool_size=1024M
  11. # mysql使用独立表空间
  12. innodb_file_per_table=1
  13. innodb_log_files_in_group=2
  14. # mysql数据文件大小,设置为1G
  15. innodb_data_file_path=ibdata1:1G:autoextend
  16. # 日志文件大小设置为512M
  17. innodb_log_file_size=512M
  18. #记录数据库全部操作,不建议开启。影响数据库5%的性能
  19. general_log=0
  20. # 日志操作记录文件
  21. general_log_file=/data/mysql5/local01.log
  22. # 开启慢日志查询
  23. slow_query_log = 1
  24. # 执行时长超过1S的SQL语句昨晚慢日志
  25. long_query_time = 1
  26. # 记录没有使用索引的查询,不建议开启,开启后分析慢日志不方便
  27. log_queries_not_using_indexes=0
  28. # 设置mysql最大连接数
  29. max_connection=3000
  30. #max_connection_error=100000
  31. # 文件打开数量 为max_connection的10倍
  32. open_files_limit=30000
  33. innodb_open_files=30000
  34. table_open_cache=30000
  35. table_definition_cache=3000
  36. # 这个要尽量的小
  37. key_buffer_size=32M
  38. #禁用查询缓存
  39. query_cache_type=0
  40. #查询缓存大小为0M
  41. query_cache_size=0
  42. # 设置数据库默认引擎
  43. default-storage-engine=INNODB
  44. # bin log 配置
  45. max_binlog_size=67108864 # 配置
  46. binlog_cache_size=1048576
  47. [mysqldump]
  48. quick
  49. max_allowed_packet = 16M
  50. [mysql]
  51. no-auto-rehash
  52. # Remove the next comment character if you are not familiar with SQL
  53. #safe-updates
  54. [myisamchk]
  55. key_buffer_size = 128M
  56. sort_buffer_size = 128M
  57. read_buffer = 2M
  58. write_buffer = 2M
  59. [mysqlhotcopy]
  60. interactive-timeout

1.6初始化Mysql

  1. ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql5

1.7启动Mysql

  1. cp support-files/mysql.server /etc/init.d/mysqld5
  2. # 打开文件/etc/init.d/mysqld5 设置datadir 和basedir
  3. # centos6 启动Mysql
  4. chkconfig add mysqld5
  5. service mysqld5 start
  6. # centos7 启动Mysql
  7. systemctl enable mysqld5
  8. systemctl start mysqld5

1.8 Mysql字符集

  1. #查看当前数据库的字符集
  2. SHOW VARIABLES LIKE '%character%'
  3. # 命令行查看当前数据库的字符集
  4. status
  5. # 查看当前数据库支持的字符集
  6. SHOW CHARACTER SET
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注