最近一個項目要部署在阿裡雲上,為了開發團隊方便,我自費買了個ECS,先裝個資料庫給開發用。 因為之前都是在真機安裝,與這次阿裡雲上的部署比起來,還是有點區別的。 Mysql 1 安裝mysql版本包 wget https://dev.mysql.com/get/mysql57-community-r ...
最近一個項目要部署在阿裡雲上,為了開發團隊方便,我自費買了個ECS,先裝個資料庫給開發用。
因為之前都是在真機安裝,與這次阿裡雲上的部署比起來,還是有點區別的。
Mysql
1 安裝mysql版本包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum install mysql57-community-release-el7-11.noarch.rpm
vim /etc/yum.repos.d/mysql-community.repo
把5.6的enable置為1,5.7的置為0
2 安裝mysql:
yum install mysql mysql-community-server -y
# 建立慢查詢日誌文件,如果沒有安裝時候會報錯
touch /var/log/slow.log
#給mysql用戶授權這個文件
chown mysql:mysql slow.log
-------------------------------配置文件------------------------------------------------
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysql]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 512M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# 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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
autocommit = 1
slow_query_log = on
slow_query_log_file =/var/log/slow.log
long_query_time = 5
# Recommended in standard MySQL setup
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
-------------------------------配置文件------------------------------------------------
因為是開發環境,沒有壓力,所以沒進行優化,實際生產時候innodb_buffer_pool_size 參數非常重要,一定要加大到記憶體70%-80%,之前吃過虧。
3 報錯
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
進入usr目錄
./mysql_install_db --user=mysql
4 啟動命令
systemctl status mysqld.service
systemctl enable mysqld.service 開機啟動
systemctl start mysqld.service 啟動mysql服務
systemctl restart mysqld.service 重啟mysql 服務
systemctl stop mysqld.service
5 初次登錄設置
mysql_secure_installation
- Set root password? [Y/n]
是否設置root用戶的密碼 - Remove anonymous users? [Y/n]
是否刪除匿名用戶 - Disallow root login remotely? [Y/n]
是否禁止root遠程登錄 - Remove test database and access to it? [Y/n]
是否刪除database資料庫 - Reload privilege tables now? [Y/n]
是否重新載入授權信息
授權遠程用戶登錄
GRANT ALL PRIVILEGES ON *.* TO '用戶名'@'%' identified by '密碼';