CentOS6.8 二进制包安装Mysql5.7

前端之家收集整理的这篇文章主要介绍了CentOS6.8 二进制包安装Mysql5.7前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS6.8 二进制包安装MysqL5.7

MysqL5.7的二进制包可以去官网直接下载,比较慢


这里如果搜索的是source code 就是找源码包了,所以要搜索 linux-generic,搜索出来的就是二进制包了。

我这里是去国内镜像网站下载的,速度快一些。
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar

  1. #创建运行MysqL的账号
  2. [root@MysqL ~]# useradd MysqL -s /sbin/nologin
  3. [root@MysqL ~]# id MysqL
  4. uid=1001(MysqL) gid=1001(MysqL) 组=1001(MysqL)
  5.  
  6. #创建MysqL相关目录
  7. [root@MysqL ~]# mkdir -p /data/MysqL/MysqL3306/{conf,data,logs,tmp}
  8. [root@MysqL ~]# chown -R MysqL.MysqL /data/MysqL/
  9.  
  10. #解压MysqL安装文件到/usr/local下
  11. [root@MysqL ~]# tar xf MysqL-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
  12. [root@MysqL ~]# ln -sv /usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64 /usr/local/MysqL
  13. "/usr/local/MysqL" -> "/usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64"
  14.  
  15. #创建MysqL配置文件
  16. [root@MysqL ~]# cat /data/MysqL/MysqL3306/conf/my.cnf
  17. [client]
  18. port = 3306
  19. socket = /tmp/MysqL3306.sock
  20.  
  21. [MysqL]
  22. prompt="\\u@\\h [\\d]>"
  23. #pager="less -i -n -S"
  24. #tee=/opt/MysqL/query.log
  25. no-auto-rehash
  26.  
  27. [MysqLd]
  28. #misc
  29. user = MysqL
  30. basedir = /usr/local/MysqL
  31. datadir = /data/MysqL/MysqL3306/data
  32. port = 3306
  33. socket = /tmp/MysqL3306.sock
  34. event_scheduler = 0
  35.  
  36. tmpdir = /data/MysqL/MysqL3306/tmp
  37. #timeout
  38. interactive_timeout = 300
  39. wait_timeout = 300
  40.  
  41. #character set
  42. character-set-server = utf8
  43.  
  44. open_files_limit = 65535
  45. max_connections = 100
  46. max_connect_errors = 100000
  47. lower_case_table_names =1
  48.  
  49. #
  50. explicit_defaults_for_timestamp=1
  51.  
  52. #symi replication
  53.  
  54. #rpl_semi_sync_master_enabled=1
  55. #rpl_semi_sync_master_timeout=1000 # 1 second
  56. #rpl_semi_sync_slave_enabled=1
  57.  
  58. #logs
  59. log-output=file
  60. slow_query_log = 1
  61. slow_query_log_file = slow.log
  62. log-error = error.log
  63. pid-file = MysqL.pid
  64. long_query_time = 1
  65. #log-slow-admin-statements = 1
  66. #log-queries-not-using-indexes = 1
  67. log-slow-slave-statements = 1
  68.  
  69. #binlog
  70. #binlog_format = STATEMENT
  71. binlog_format = row
  72. server-id = 1013306
  73. log-bin = /data/MysqL/MysqL3306/logs/MysqL-bin
  74. binlog_cache_size = 1M
  75. max_binlog_size = 256M
  76. sync_binlog = 0
  77. expire_logs_days = 10
  78. #procedure
  79. log_bin_trust_function_creators=1
  80.  
  81. #
  82. gtid-mode = on
  83. enforce-gtid-consistency=1
  84.  
  85. #relay log
  86. skip_slave_start = 1
  87. max_relay_log_size = 128M
  88. relay_log_purge = 1
  89. relay_log_recovery = 1
  90. relay-log=relay-bin
  91. relay-log-index=relay-bin.index
  92. log_slave_updates
  93. #slave-skip-errors=1032,1053,1062
  94. #skip-grant-tables
  95.  
  96. #buffers & cache
  97. table_open_cache = 2048
  98. table_definition_cache = 2048
  99. table_open_cache = 2048
  100. max_heap_table_size = 96M
  101. sort_buffer_size = 128K
  102. join_buffer_size = 128K
  103. thread_cache_size = 200
  104. query_cache_size = 0
  105. query_cache_type = 0
  106. query_cache_limit = 256K
  107. query_cache_min_res_unit = 512
  108. thread_stack = 192K
  109. tmp_table_size = 96M
  110. key_buffer_size = 8M
  111. read_buffer_size = 2M
  112. read_rnd_buffer_size = 16M
  113. bulk_insert_buffer_size = 32M
  114.  
  115. #myisam
  116. myisam_sort_buffer_size = 128M
  117. myisam_max_sort_file_size = 10G
  118. myisam_repair_threads = 1
  119.  
  120. #innodb
  121. innodb_buffer_pool_size = 100M
  122. innodb_buffer_pool_instances = 1
  123. innodb_data_file_path = ibdata1:100M:autoextend
  124. innodb_flush_log_at_trx_commit = 2
  125. innodb_log_buffer_size = 8M
  126. innodb_log_file_size = 100M
  127. innodb_log_files_in_group = 3
  128. innodb_max_dirty_pages_pct = 50
  129. innodb_file_per_table = 1
  130. innodb_rollback_on_timeout
  131. innodb_status_file = 1
  132. innodb_io_capacity = 2000
  133. transaction_isolation = READ-COMMITTED
  134. innodb_flush_method = O_DIRECT
  135.  
  136. loose_tokudb_cache_size=100M
  137. loose_tokudb_directio=ON
  138. loose_tokudb_fsync_log_period=1000
  139. loose_tokudb_commit_sync=0
  140.  
  141. #初始化MysqL
  142. [root@MysqL ~]# /usr/local/MysqL/bin/MysqLd --defaults-file=/data/MysqL/MysqL3306/conf/my.cnf --initialize
  143.  
  144. #获取初始化生成的密码
  145. [root@MysqL ~]# cat /data/MysqL/MysqL3306/data/error.log | grep password | awk '{print $NF}'
  146. H=?ycalZA4.e
  147.  
  148. #启动MysqL
  149. [root@MysqL ~]# /usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64/bin/MysqLd --defaults-file=/data/MysqL/MysqL3306/conf/my.cnf &
  150. [1] 4596
  151. [root@MysqL ~]# ss -tnl
  152. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  153. LISTEN 0 128 *:22 *:*
  154. LISTEN 0 100 127.0.0.1:25 *:*
  155. LISTEN 0 70 :::3306 :::*
  156. LISTEN 0 128 :::22 :::*
  157. LISTEN 0 100 ::1:25 :::*
  158. [root@MysqL ~]# ps aux |grep MysqL
  159. MysqL 4596 3.8 17.8 1077724 181116 pts/0 Sl 04:01 0:00 /usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64/bin/MysqLd --defaults-file=/data/MysqL/MysqL3306/conf/my.cnf
  160. root 4632 0.0 0.0 112656 972 pts/0 R+ 04:01 0:00 grep --color=auto MysqL
  161.  
  162. #连接到数据库
  163. [root@MysqL ~]# /usr/local/MysqL/bin/MysqL -u root -p -S /tmp/MysqL3306.sock
  164. Enter password: #这输入的是上文中获取到的密码
  165. Welcome to the MysqL monitor. Commands end with ; or \g.
  166. Your MysqL connection id is 4
  167. Server version: 5.7.20-log
  168.  
  169. Copyright (c) 2000,2017,Oracle and/or its affiliates. All rights reserved.
  170.  
  171. Oracle is a registered trademark of Oracle Corporation and/or its
  172. affiliates. Other names may be trademarks of their respective
  173. owners.
  174.  
  175. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  176.  
  177. #第一次操作室要求修改密码
  178. MysqL> show databases;
  179. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  180.  
  181. #修改root用户的密码为123456
  182. MysqL> alter user user() identified by '123456';
  183. Query OK,0 rows affected (0.00 sec)
  184.  
  185. MysqL> show databases;
  186. +--------------------+
  187. | Database |
  188. +--------------------+
  189. | information_schema |
  190. | MysqL |
  191. | performance_schema |
  192. | sys |
  193. +--------------------+
  194. 4 rows in set (0.00 sec)
  195.  
  196. #用新密码重新登陆
  197. [root@MysqL ~]# /usr/local/MysqL/bin/MysqL -u root -p123456 -S /tmp/MysqL3306.sock
  198. MysqL: [Warning] Using a password on the command line interface can be insecure.
  199. Welcome to the MysqL monitor. Commands end with ; or \g.
  200. Your MysqL connection id is 5
  201. Server version: 5.7.20-log MysqL Community Server (GPL)
  202.  
  203. Copyright (c) 2000,Oracle and/or its affiliates. All rights reserved.
  204.  
  205. Oracle is a registered trademark of Oracle Corporation and/or its
  206. affiliates. Other names may be trademarks of their respective
  207. owners.
  208.  
  209. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  210.  
  211. MysqL>

关闭MysqL数据库

#通过MysqLadmin接口关闭数据库
[root@MysqL ~]# /usr/local/MysqL/bin/MysqLadmin -u root -p123456 -S /tmp/MysqL3306.sock shutdown
MysqLadmin: [Warning] Using a password on the command line interface can be insecure.

#检查结果[root@MysqL ~]# ss -tnl |grep 3306[root@MysqL ~]# ps aux |grep MysqL |grep -v grep

猜你在找的CentOS相关文章