mysql-5.7在CentOS-7下的rpm安装
0.安装MySQL前准备
安装MySQL依赖包
systemctl stop postfix
systemctl disable postfix
yum remove postfix
yum install libaio perl net-tools -y
创建数据文件目录
mkdir -p /opt/mysql/{data,binlog}
1.卸载系统自带的mariadb软件包
检查系统中存在的mariadb-lib:rpm -qa|grep mariadb
或者yum list installed | grep mariadb
在mini安装的CentOS-7.4中,存在:mariadb-libs-5.5.56-2.el7.x86_64
删除: rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
或者yum remove mariadb-libs.x86_64
2.从MySQL官网下载并解压:mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
,依次安装4个包:
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
3.初始化数据库
编辑/etc/my.cnf
,更改数据文件路径:
[mysqld]
datadir=/opt/mysql/data
socket=/tmp/mysqld.sock
symbolic-links=0
log-error=/opt/mysql/mysqld.log
pid-file=/opt/mysql/mysqld.pid
[client]
socket=/tmp/mysqld.sock
修改完成后,进行MySQL初始化:
chown mysql.mysql -R /opt/mysql
chown mysql.mysql -R /etc/my.cnf
chmod 750 -R /opt/mysql
mysqld --initialize --user=mysql
systemctl start mysqld.service
systemctl enable mysqld
systemctl daemon-reload
systemctl status mysqld
初始化完成后会在/mysql/mysqld.log
生成随机密码,使用:grep 'temporary password' /mysql/mysqld.log
查看随机密码
4.用随机密码登录,修改密码,并设置远程访问
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass8!';
mysql> use mysql;
mysql> Grant all on *.* to 'root'@'%' identified by 'root用户的密码' with grant option;
mysql> flush privileges;
mysql> select user,host from user;
5.创建其他管理用户
mysql> create user 'admin'@'%' identified by 'password';
mysql> GRANT ALL PRIVILEGES ON dbname.* to 'admin'@'%';
mysql> flush privileges