您好,登錄后才能下訂單哦!
本篇內容介紹了“如何安裝MySQL二進制包”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
本文使用二進制包安裝及簡單配置MySQL-v5.6.51版本。
5.6版本下載:
https://downloads.mysql.com/archives/community/
在此URL地址頁面中的“Product Version”選擇5.6的相應版本。
本文中使用本地VM虛機部署測試。
OS:CentOS Linux release 7.8.2003 (Core) 3.10.0-1160.15.2.el7.x86_64
虛機配置:2核CPU、4G內存
## 查詢已安裝的mariadb
rpm -qa |grep mariadb
## 卸載mariadb軟件包,文件名為上述命令查詢出來的文件
rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
## 創建數據保存目錄 mkdir -p /data/mysql ## 創建用戶組mysql groupadd -r mysql ## 創建用戶mysql并設置不能登錄系統,指定宿主目錄 useradd -g mysql -r -s /sbin/nologin -M -d /data/mysql mysql ## 修改數據保存目錄屬性及權限 chown mysql.mysql /data/mysql chmod 0700 /data/mysql
cd /data/tools wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ cd /usr/local ## 創建軟鏈接,方便后續操作 ln -sv mysql-5.6.51-linux-glibc2.12-x86_64 mysql
vi /etc/my.cnf //輸入以下內容 [client] port = 3306 socket = /usr/local/mysql/mysql.sock default-character-set = utf8mb4 [mysqld] port = 3306 socket = /usr/local/mysql/mysql.sock basedir = /usr/local/mysql datadir = /data/mysql character-set-server = utf8mb4 collation-server = utf8mb4_general_ci init_connect = 'SET NAMES utf8mb4' server-id = 1 log-slave-updates = true skip-external-locking skip-name-resolve key_buffer_size = 256M max_allowed_packet = 64M table_open_cache = 256 sort_buffer_size = 16M read_buffer_size = 8M read_rnd_buffer_size = 64M myisam_sort_buffer_size = 256M thread_cache_size = 16 query_cache_size = 128M query_cache_type = 1 log-bin = mysql-bin binlog_format = row expire_logs_days = 30 slow_query_log = on long_query_time = 2 slow_query_log_file = /data/mysql/db-slow.log gtid-mode = on enforce-gtid-consistency = true default-storage-engine = INNODB innodb_additional_mem_pool_size = 64M innodb_buffer_pool_size = 1G innodb_data_file_path = ibdata1:10M:autoextend innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 8 innodb_flush_log_at_trx_commit = 1 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 = 60 innodb_file_per_table = on max_connections = 5000 interactive_timeout = 28800 wait_timeout = 28800 sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp = true [mysqldump] quick max_allowed_packet = 32M [mysql] no-auto-rehash default-character-set = utf8mb4 [myisamchk] key_buffer_size = 128M sort_buffer_size = 128M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] log-error = /data/mysql/mysql_err.log pid-file = /data/mysql/mysqld.pid
注:參數可根據實際環境需求進行修改,此處配置僅供參考。
cd /usr/local/mysql chown -R mysql.mysql .
cd /usr/local/mysql scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
注:5.6版本使用mysql_install_db命令初始化數據,針對root@localhost用戶不設置臨時密碼,客戶端可以直接通過mysql命令登錄數據庫系統。
cd /usr/local/mysql ## 幫助文件 echo "MANPATH /usr/local/mysql/man" >> /etc/man.config ## 頭文件 ln -sv /usr/local/mysql/include /usr/include/mysql ## lib庫 echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf ## 加載動態庫文件 ldconfig
echo '######MySQL' >> /etc/profile echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile
cd /usr/local/mysql cp support-files/mysql.server /etc/rc.d/init.d/mysqld
/etc/init.d/mysqld start /usr/local/mysql/bin/mysql --version && echo -e "\e[31m mysql install is OK\e[0m"
echo -e "delete from mysql.user where user='';" | mysql -uroot -p //提示輸入密碼,直接Enter鍵確認 echo -e "delete from mysql.user where host='::1';" | mysql -uroot -p echo -e "drop database test;" | mysql -uroot -p
mysql -uroot -p //因初始化數據時沒有設置密碼,可以按兩次確認鍵進入數據庫 mysql> use mysql; mysql> update user set password = PASSWORD('123456') where user = 'root'; mysql> FLUSH PRIVILEGES;
# mysql -uroot -p //輸入上述步驟中設置的密碼登錄數據庫 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES;
啟動:/etc/init.d/mysqld start
關閉:/etc/init.d/mysqld stop
重啟:/etc/init.d/mysqld restart
查看狀態:/etc/init.d/mysqld status
配置開機啟動:echo "/etc/init.d/mysqld start" >> /etc/rc.local
“如何安裝MySQL二進制包”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。