1、先安裝依賴套件
yum install -y gcc gcc-c++ ncurses-devel perl openssl-devel
最最重要的是,不要忘了安裝openssl-devel
(免費學習影片教學推薦:mysql影片教學)
2、安裝cmake
tar -xzvf cmake-3.8.1.tar.gz cd cmake-3.8.1 ./bootstrap make && make install
3、安裝MySQL5.7.18
先下載安裝包,本人的安裝版本是:mysql-boost-5.7.18.tar.gz
需要下載boost,本人配套的是boost_1_59_0版本
下載,並在/usr/local目錄下解壓,並重新命名為boost
首先為新增MySQL 對應的系統帳戶,用於保證其本機檔案權限指派:
groupadd mysql useradd -r -g mysql mysql
建立資料庫目錄:
mkdir -p /var/mysql/data chown mysql:mysql /var/mysql/data
進入解壓縮後的MySQL安裝套件:
cd mysql-boost-5.7.18 cmake . \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \ -DINSTALL_DATADIR=/usr/local/mysql/data/master \ -DSYSCONFDIR=/usr/local/mysql/etc \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -DWITH_SSL=system \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_USER=mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/boost
如果發生錯誤,修改好後,需要刪除目前目錄下的CMakeCache.txt文件,再重新cmake
make && make install
進行完以上步驟,需要改變mysql 安裝目錄的擁有者,例如我們安裝的目錄是/usr/local/mysql,使用指令
chown -R mysql:mysql /usr/local/mysql
修改目錄擁有者。此時,複製一份預設設定檔
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
部落客安裝完成沒有my-default.cnf 這個文件,需要自己創建,附上檔案的內容:
#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] #aracter_set_server=utf8 #init_connect='SET NAMES utf8' sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # 一般配置选项 basedir = /usr/local/mysql datadir = /usr/local/mysql/data/master port = 3306 socket = /usr/local/mysql/data/mysql.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] port=3306 socket=/usr/local/mysql/data/mysql.sock #default-character-set=utf8
如果提示已存在文件是否覆蓋時,覆蓋即可。
然後執行資料庫的初始化操作,
/usr/local/mysql/bin/mysqld --initialize --user=mysql,
這時候會初始化資料庫並建立一個資料庫root 帳號,但是要注意,這個帳號是有預設密碼的,初始化的時候螢幕上會輸出初始化的密碼,如果錯過了,可以透過檢視/root/.mysql_secret 即可看到預設的密碼。
執行 cp /usr/local/mysql/support-files/mysql.server /etc/init.d,將 mysql 的服務啟動腳本複製過去,然後執行 service mysql.server start 啟動 mysql。
最後/usr/local/mysql/bin/mysql -rroot -p,輸入密碼回車,如果出現Access denied for user 'root'@'localhost' (using password: YES),一般情況下
service mysql.server restart 重新啟動即可
通過之後,可以用以下指令重新設定root密碼
set password=password('你的密码');
至此,基本的安裝流程完畢
#以下方法可以設定開機啟動
指令echo "service mysqld start" >> /etc/rc.local
或進入/etc/目錄,直接vim rc.local編輯rc.local文件,在最後一行新增「service mysqld start」,儲存退出。
以上是centos系統下安裝MySQL5.7.18方法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!