溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

【MySQL】標(biāo)準(zhǔn)化安裝教程

發(fā)布時間:2020-07-06 05:35:42 來源:網(wǎng)絡(luò) 閱讀:246 作者:wangkunj 欄目:MySQL數(shù)據(jù)庫

導(dǎo)讀:
本文主要介紹 CentOS 系統(tǒng)二進(jìn)制安裝 MySQL 5.7.23 版本的安裝步驟,其他版本安裝過程相似。

1.前置準(zhǔn)備
  • 卸載舊版MySQL

    • 查看rpm包

    rpm -qa|grep mysql 若有可用rpm -e卸載

    • 查找mysql殘留包,有則刪除,沒有則忽略

    find / -name mysql

  • 安裝相關(guān)依賴

    yum -y install make gcc-c++ cmake bison-devel ncurses-devel numactl libaio

  • 創(chuàng)建用戶和用戶組

    groupadd mysql
    useradd -s /sbin/nologin -g mysql -M mysql

2.下載二進(jìn)制安裝包并解壓
cd /usr/local/
# wget下載或者本地下載后上傳
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 解壓安裝包
tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 解壓后為了方便后面操作可把解壓后文件名修改為mysql
mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql
# 更改文件夾所屬
chown -R mysql.mysql /usr/local/mysql/
3.創(chuàng)建mysql相關(guān)目錄
mkdir -p /data/mysql/{data,logs,tmp}
# 更改文件夾所屬
chown -R mysql.mysql /data/mysql/
4.創(chuàng)建mysql配置文件my.cnf
vi /etc/my.cnf
# 簡單模板如下:
[client]
port            = 3306
socket          = /data/mysql/tmp/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql        
datadir = /data/mysql/data  
port = 3306               

socket = /data/mysql/tmp/mysql.sock
pid-file  = /data/mysql/tmp/mysqld.pid
tmpdir = /data/mysql/tmp    
skip_name_resolve = 1
symbolic-links=0
max_connections = 2000
group_concat_max_len = 1024000
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1
log_timestamps=SYSTEM
character-set-server = utf8
interactive_timeout = 1800  
wait_timeout = 1800
max_allowed_packet = 32M
binlog_cache_size = 4M
sort_buffer_size = 2M
read_buffer_size = 4M
join_buffer_size = 4M
tmp_table_size = 96M
max_heap_table_size = 96M
max_length_for_sort_data = 8096

#logs
server-id = 1003306
log-error = /data/mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 3
log-bin = /data/mysql/logs/binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
relay-log = /data/mysql/logs/relay-bin
relay-log-recovery = 1  
relay_log_purge = 1  

#innodb  
innodb_file_per_table = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_flush_method = O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_size = 2G
5.配置mysql.server
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
# 修改目錄位置
basedir=/usr/local/mysql
datadir=/data/mysql/data

# 注冊開機(jī)啟動服務(wù)
chkconfig --add mysql
chkconfig --list
6.添加環(huán)境變量
echo "PATH=$PATH:/usr/local/mysql/bin  " >> /etc/profile  
source /etc/profile
7.初始化mysql
/usr/local/mysql/bin/mysqld  --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
# 臨時密碼保存在errlog中 
# 獲取臨時密碼
more /data/mysql/logs/error.log |grep password
8.啟動mysql服務(wù) 并修改密碼
# 啟動mysql服務(wù)
service mysql start
# 使用初始密碼登錄mysql服務(wù) 并修改密碼
mysql -uroot -p
alter user 'root'@'localhost' identified by 'root';
flush privileges;

【MySQL】標(biāo)準(zhǔn)化安裝教程

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI