1. 程式人生 > >Linux下MySQL5.7.18二進位制包安裝(無預設配置檔案my_default.cnf)

Linux下MySQL5.7.18二進位制包安裝(無預設配置檔案my_default.cnf)

最新在學習MySQL,純新手,對Linux瞭解的也不多,因為是下載的最新版的MySQL(MySQL5.7.18)二進位制包,CentOS7.2下測試安裝,方便以後折騰。
大概步驟如下,安裝刪除反覆折騰了幾遍,按照以下步驟,應該沒啥問題了。
也沒有想象中的複雜,大部分步驟都是參考網上的,照做就是了,出錯的話,多嘗試,多查資料。

 

作業系統版本

   技術分享

建立mysql組和使用者

   技術分享

 

下載最新版的MySQL 5.7.18二進位制包,上傳至伺服器的usr/local目錄下

技術分享

 

解壓MySQL二進位制包

技術分享

 

如下是解壓之後的,並且重新命名資料夾之後的檔案資訊

技術分享

 

更改所屬的組和使用者

技術分享

 

解壓之後的MySQL檔案包含的內容

技術分享

 

檢視support-files資料夾的內容,發現並沒有my_default.cnf預設的配置檔案,如果沒有預設的配置檔案,需要手動建立一個my_default.cnf配置檔案

技術分享

 

從網上找了一個配置檔案,如下,上傳到support-files資料夾中,當然這個配置檔案可以根據需要自行修改

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

# 一般配置選項
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /var/run/mysqld/mysqld.sock
character-set-server=utf8


back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M

max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8

thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6

server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M

innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on

[mysqldump]
quick

max_allowed_packet = 32M

[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates

[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 8192

[client]
/bin/bash: Q: command not found

 

如下,將上述預設配置檔案上傳至support-files資料夾中

技術分享

 

註冊和初始化MySQL服務

  這一點比較坑,網上的教程大多是mysql_install_db 方式安裝的,這一步也是遇到問題最最多的,折騰了好久,但是mysql_install_db 命令是不推薦的,也提示使用mysqld來安裝
  在安裝mysql 5.7.18的時候也是各種報錯,經過各種嘗試之後吧,採用如下命名方式安裝,只要沒有Error,警告資訊Warning先不理它

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

技術分享

 

複製上述的my_default.cnf和mysql.server配置檔案到etc目錄,之前複製過該檔案到etc目錄,它這裡提示是否覆蓋,輸入Y覆蓋

[[email protected] mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld

技術分享

 

啟動MySQL服務

啟動命令:service mysql start   

重啟命令: service mysql restart 

技術分享

 

連線至MySQL,預設沒有密碼,直接回車後連線至MySQL

 技術分享

 

修改MySQL的root密碼

 技術分享

技術分享

修改可遠端訪問

技術分享

  

重啟MySQL服務

技術分享

此時本地可以正常使用MySQL

技術分享

 

 

測試遠端連線

技術分享