Linux下二进制包安装mysql-5.7.14

mysql5.7的安装和mysql5.6的安装变化蛮大的.我一开始按照官方文档的说明安装的,根本不行,不得不吐槽一下mysql的官方安装文档很差,和mongodb的没法比.
注意:在使用二进制包安装mysql的时候,确保你的系统上没有以前的使用yum或者rpm安装的旧的mysql,如果存在,使用rpm -e命令来删除.包括删除/etc/my.cnf
下面是安装步骤:

1.创建mysql用户和组

 
    
  1. groupadd mysql
  2. useradd -r -g mysql -s /bin/false mysql

2.解压缩安装包

 
    
  1. tar zxvf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
  2. cd /usr/local
  3. ln -sv mysql-5.7.14-linux-glibc2.5-x86_64 mysql

3.创建数据文件目录并且赋权

 
    
  1. cd /usr/local/mysql
  2. chown -R mysql.mysql *

这里我将mysql数据文件放在/data/mysql/data下
 
    
  1. mkdir -p /data/mysql/data
  2. chown -R mysql:mysql /data/mysql/data

4.创建mysql配置文件

这里我直接拷贝了以前使用的my.cnf,其中有些参数已经被遗弃.数据目录,日志目录根据现实环境修改:
 
    
  1. vi /etc/my.conf
  2. [mysqld]
  3. ###################BASIC#################
  4. port = 3306
  5. user = mysql
  6. socket = /data/mysql/data/mysql.sock
  7. pid-file = /data/mysql/data/mysql.pid
  8. basedir = /usr/local/mysql
  9. datadir = /data/mysql/data
  10. #skip-name-resolve
  11. #skip-grant-tables
  12. skip-external-locking
  13. character-set-server=utf8
  14. default-storage-engine = innodb
  15. lower_case_table_names=1
  16. ##################CONNECT#################
  17. max_connections = 2000
  18. max_connect_errors = 1000000
  19. interactive_timeout = 28800
  20. wait_timeout = 28800
  21. connect_timeout = 20
  22. back_log = 500
  23. #FOR FAST CREATE THREAD
  24. thread_cache_size = 300
  25. open_files_limit = 10240
  26. table_open_cache = 3000
  27. ###############THREAD BUFFER##############
  28. ###############FOR EVERY THREAD###########
  29. sort_buffer_size = 1M
  30. join_buffer_size = 1M
  31. read_buffer_size = 1M
  32. read_rnd_buffer_size = 1M
  33. #net_buffer_length = 16k
  34. tmp_table_size = 64M
  35. max_allowed_packet = 128M
  36. #FOR MEMORY ENGINE
  37. max_heap_table_size = 64M
  38. #################BUFFER##################
  39. ###############FOR ALL THREAD############
  40. query_cache_type = 0
  41. query_cache_size = 32M
  42. query_cache_limit = 1M
  43. #################LOG BUFFER#############
  44. binlog_cache_size = 16M
  45. max_binlog_cache_size = 32M
  46. binlog_stmt_cache_size = 32M
  47. #################LOG FILE###############
  48. sync_binlog = 0
  49. binlog_format = row
  50. log-error = /data/mysql/log/mysql-err.log
  51. log-bin = /data/mysql/log/master-bin
  52. max_binlog_size = 512M
  53. relay-log = /data/mysql/log/relay-bin
  54. log_output = file
  55. slow_query_log = 1
  56. slow_query_log_file = /data/mysql/log/slow_query.log
  57. long_query_time=10
  58. general_log = 0
  59. general_log_file = /data/mysql/log/general_query_log
  60. expire-logs-days = 3
  61. ###############INNODB##################
  62. #innodb_page_size = 16k
  63. innodb_file_per_table = 1
  64. #innodb_data_file_path = ibdata1:12M:autoextend
  65. #innodb_log_file_size = 512M
  66. #innodb_log_files_in_group = 3
  67. #innodb_buffer_pool_size = 500M
  68. #innodb_buffer_pool_instance=8
  69. innodb_log_buffer_size = 8m
  70. innodb_max_dirty_pages_pct = 90
  71. innodb_thread_concurrency = 0
  72. innodb_flush_method = O_DIRECT
  73. innodb_flush_log_at_trx_commit = 0
  74. innodb_lock_wait_timeout = 100
  75. innodb_fast_shutdown = 1
  76. innodb_read_io_threads = 8
  77. innodb_write_io_threads = 8
  78. innodb_io_capacity = 1000
  79. innodb_use_native_aio = 1
  80. innodb_stats_on_metadata = 0
  81. innodb_strict_mode = 1
  82. innodb_file_format = barracuda
  83. innodb_file_format_max = barracuda
  84. innodb_file_format_check = 1
  85. ###############MYISAM###################
  86. key_buffer_size = 64M
  87. key_cache_block_size = 64k
  88. myisam_sort_buffer_size = 64M
  89. #################REPLICATE###############
  90. server_id =1
  91. log_slave_updates=1
  92. #binlog-do-db = brent
  93. #binlog-ignore-db = mysql
  94. #replicate_ignore_db=mysql
  95. #replicate_do_table=brent.t1
  96. #replicate_ignore_table=brent.t2
  97. #######GTID#######
  98. #gtid-mode = on
  99. #enforce-gtid-consistency = true
  100. #master-info-repository=TABLE
  101. #master-info-repository=TABLE
  102. #relay-log-info-repository=TABLE
  103. #sync-master-info=1
  104. #slave-parallel-workers=2
  105. #binlog-checksum=CRC32
  106. #master-verify-checksum=1
  107. #slave-sql-verify-checksum=1
  108. #binlog-rows-query-log_events=1
  109. #report-port=3306
  110. #report-host=localip
  111. sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  112. [mysqld_safe]
  113. err-log = /data/mysql/log/mysqld_safe.log
  114. pid-file = /data/mysql/data/mysql.pid
  115. [mysql]
  116. no-auto_rehash
  117. default_character-set = gbk
  118. [client]
  119. port = 3306
  120. socket = /data/mysql/data/mysql.sock


5.初始化mysql

在5.6初始化使用scripts/mysql_install_db来实现,而5.7.6以后的版本则使用bin/mysqld --initialize来实现
根据上面的my.conf来初始化:
 
    
  1. cd /usr/lcoal/mysql
  2. bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data --pid-file=/data/mysql/data/mysql.pid
  3. chown -R root .

6.将mysql设置为服务

 
    
  1. cp support-files/mysql.server /etc/init.d/mysqld
  2. chkconfig --add mysqld
  3. chkconfig --level 35 mysqld on

7.启动连接mysql

这时你就可以启动mysql了
 
    
  1. service mysqld start
5.7以后root密码写在/root/.mysql_secret下
 
    
  1. cat /root/.mysql_secret
  2. mysql -uroot -p
  3. Enter password:

8.其他

我这里安装完成之后使用.mysql_secret的密码总是报错密码错误.解决办法是,
先在my.cnf中添加skip-grant-tables参数来跳过授权表
然后启动数据库.再执行下面的语句:
 
    
  1. mysql> flush privileges;
  2. Query OK, 0 rows affected (0.32 sec)
  3. mysql> set password for root@'localhost'=password('root');
  4. Query OK, 0 rows affected, 1 warning (0.00 sec)
  5. mysql> flush privileges;
  6. Query OK, 0 rows affected (0.00 sec)
mysql5.7的mysql.user中不再存放passwod列,因此不能直接update了.















你可能感兴趣的:(mysql管理)