1、查看下面软件包是否安装,如果安装卸载。
# rpm -qa | grep postfix
# rpm -qa | grep mariadb
# rpm -qa | grep mysql
2、创建目录
创建包存放目录
# mkdir /data/packages
创建mysql数据目录
# mkdir /data/mysql_data
3、解压并安装
# cd /data/packages
# tar -xf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar
# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm
4、赋予权限并设置开机自启动
# chown mysql:mysql /data/mysql_data
# systemctl enable mysqld.service
5、编辑配置文件
# vi /etc/my.cnf
[mysql]
default-character-set=utf8
datadir=/data/mysql_data
default-storage-engine=INNODB
character_set_server=utf8
expire_logs_days=15
innodb_buffer_pool_size=8G
innodb_log_file_size=256M
innodb_flush_method=O_DIRECT
max_connections=500
innodb_autoextend_increment=128
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
6、启动服务并设置登录密码
# systemctl start mysqld.service
查看初始密码
# grep "root@localhost" /var/log/mysqld.log | awk '{print $11}'
使用初始密码登录并修改密码
# mysql -uroot -p
mysql> set password=password('自定义密码');