一、到官網(wǎng)下載mysql-5.7.22二進(jìn)制包
創(chuàng)新互聯(lián)是一家專業(yè)從事網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站的網(wǎng)絡(luò)公司。作為專業(yè)網(wǎng)站制作公司,創(chuàng)新互聯(lián)依托的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、全網(wǎng)營銷推廣及網(wǎng)站設(shè)計(jì)開發(fā)服務(wù)!二、創(chuàng)建mysql用戶:
useradd mysql -s /sbin/nologin -M
三、解壓mysql-5.7.22-el7-x86_64.tar.gz :
tar xf mysql-5.7.22-el7-x86_64.tar.gz && mv mysql-5.7.22-el7-x86_64.tar.gz /opt/mysql
四、創(chuàng)建相關(guān)目錄:
cd /opt/mysql mkdir {data,logs,etc} mkidr logs/binlog
五、修改權(quán)限:
cd /opt/ && chown -R mysql.mysql mysql
六、初始化數(shù)據(jù)庫:
cd /opt/mysql
./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
記住最后提示的密碼
七、修改my.cnf文件:
echo > /etc/my.cnf vi my.cnf 加入文檔最后的內(nèi)容
八、配置mysql服務(wù):
cd /opt/mysql && cp support-files/mysql.server /etc/init.d/mysqld
修改權(quán)限chmod +x /etc/init.d/mysqld
編輯mysqld加入basedir=/opt/mysql datadir=/opt/mysql/data
chkconfig --add mysqld
九、啟動(dòng)mysql服務(wù):
service mysqld start
此時(shí)會(huì)報(bào)日志錯(cuò)誤:Starting MySQL.2018-07-26T14:24:53.192088Z mysqld_safe error: log-error set to '/opt/mysql/logs/mysql-error.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/opt/mysql/data/mysql.pid).
原因是找不到logs下的mysql-error.log文件
我們手動(dòng)創(chuàng)建一個(gè)
touch /opt/mysql/logs/mysql-error.log&&chown mysql.mysql mysql-error.log
再執(zhí)行service mysqld start 即可
十、配置環(huán)境變量:
cd &&vi .bash_profile 在PATH后加上/opt/mysql/bin,保存退出
執(zhí)行source .bash_profile
十一、登錄數(shù)據(jù)庫,修改密碼:
啟動(dòng)服務(wù)后,執(zhí)行mysql -uroot -p 輸入初始化時(shí)的密碼
執(zhí)行show databases; 會(huì)報(bào)錯(cuò)ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
執(zhí)行set PASSWORD=PASSWORD('123456'); flush privileges 修改密碼
退出后用新密碼可以重新登錄
至此,Mysql-5.7.22二進(jìn)制方式安裝完成
[mysqld]
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir=/opt/mysql #介質(zhì)目錄
datadir=/opt/mysql/data #數(shù)據(jù)目錄
port=3306 #端口
pid-file = /opt/mysql/data/mysql.pid #進(jìn)程id
user = mysql #啟動(dòng)用戶
socket=/opt/mysql/data/mysql.sock #sock文件地址
bind-address = 0.0.0.0 #綁定ip 這里表示綁定所有ip
server-id = 1 #用于復(fù)制環(huán)境鐘標(biāo)識實(shí)例,這個(gè)在復(fù)制環(huán)境里唯一
character-set-server = utf8 #服務(wù)端默認(rèn)字符集,很重要,錯(cuò)誤設(shè)置會(huì)出現(xiàn)亂碼
max_connections = 1000 #允許客戶端并發(fā)連接的大數(shù)量
max_connect_errors = 6000 #如果客戶端嘗試連接的錯(cuò)誤數(shù)量超過這個(gè)參數(shù)設(shè)置的值,則服務(wù)器不再接受新的客戶端連接。
open_files_limit = 65535 #操作系統(tǒng)允許MySQL服務(wù)打開的文件數(shù)量。
table_open_cache = 128 #所有線程能打開的表的數(shù)量
max_allowed_packet = 4M #網(wǎng)絡(luò)傳輸時(shí)單個(gè)數(shù)據(jù)包的大小。
back_log= 300
binlog_cache_size = 4M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /opt/mysql/logs/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /opt/mydql/logs/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[client]
port=3306
socket=/opt/mysql/data/mysql.sock
[mysql]
no-auto-rehash
#default-character-set=utf8
safe-updates
socket=/opt/mysql/data/mysql.sock
[mysqldump]
quick
max_allowed_packet = 32M
[mysqlhotcopy]
interactive-timeout
[mysql_safe]
open-files-limit = 8192
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。