1.軟件環(huán)境
1.服務(wù)器:centos 6.5
2.數(shù)據(jù)庫版本:mysql-5.7.20
2.安裝前檢查系統(tǒng)
1.檢查系統(tǒng)是否包含libaio 包
yum search libaio // 查詢
yum install libaio // 安裝
2.檢查系統(tǒng)是否安裝mariadb數(shù)據(jù)庫,centos系統(tǒng)默認安裝的數(shù)據(jù)庫,會在/etc目錄下生成my.cnf文件欺劳,該文件可能會導致安裝mysql發(fā)生異常,所以建議直接將mariadb卸載
rpm -qa | grep mari* // 查詢是否安裝了maridb
rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps // 忽略依賴卸載軟件
3.安裝mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
#此步執(zhí)行完畢后,會將臨時密碼打印在控制臺上航夺,可以用此密碼進入mysql
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysqld
#開機啟動
chkconfig mysqld on
4.配置數(shù)據(jù)庫
1.將mysqld加入環(huán)境變量中
vim /etc/profile
#在最后加上
export PATH=$PATH:YOUR MYSQL PATH/bin
2.修改密碼
alter user user() identified by "password";
flush privileges;
exit;
3.修改mysql配置文件,在etc目錄下創(chuàng)建my.cnf文件
touch /etc/my.cnf
vim /etc/my.cnf
#寫入如下內(nèi)容
[mysqld]
basedir = 你的mysql路徑
datadir = 你的mysql數(shù)據(jù)文件路徑
port=3306
server-id = 1
character-set-server = utf8
general_log = 1
skip-name-resolve
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
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 = 28M
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
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
myisam_sort_buffer_size = 8M
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
[client]
#socket =/data/db/mysql-5.7.12/mysql.sock
4.重啟數(shù)據(jù)庫
service mysqld restart
5.授權(quán)遠程訪問
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION