阿里云CentOS安装Mysql
- 查看当前应用中是否存在已经安装的mysql
ps -ef|grep mysql
- 如果存在,
pkill -9 mysqld
- 删除mysql相关组件
rpm -qa|grep -i mysql
yum -y remove mysql-community-client-5.6.38-2.el7.x86_64
- 安装
cd /usr/local/src/
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server
- 默认配置文件路径
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
- 配置
/etc/my.cnf
配置文件
[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 = 128M
#
# 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
server_id = 1
expire_logs_days = 3
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
- 启动mysql
service mysqld restart
- 获取开始的随机密码
grep "password" /var/log/mysqld.log
示例:
2018-12-29T06:12:45.992339Z 1 [Note] A temporary password is generated for root@localhost: 4CgdNQiq0a:<
4CgdNQiq0a:<便为初始随机密码
- 登录
mysql -u root -p 密码
- 修改密码
alter user 'root'@'localhost' identified by 'Root!!2018';
flush privileges
9.关闭防火墙
10.如果是阿里云注意添3306端口为安全策略
- 允许其他ip远程登录
grant all privileges on *.* to 'root'@'%' identified by 'Root!!2018' with grant option;
flush privileges;
ok