阿里云centOS7.4上MySql5.6安装

最近一个项目要部署在阿里云上,为了开发团队方便,我自费买了个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 '密码';

上一篇:SQLServer查询速度慢的原因


下一篇:乔纳森AMA合集【中文版】