关闭selinux
# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
重启后生效
# sestatus
修改提示符配置
# vi /etc/bashrc
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ "
# source /etc/bashrc
安装依赖包
# rpm -ivh libaio-devel-0.3.109-13.el7.x86_64.rpm
卸载mariadb相关包
# rpm -qa|grep mariadb
# yum remove -y mariadb-libs
创建用户
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
解压并创建软链接
# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
# ln -s /usr/local/mysql-5.7.26-linux-glibc2.12-x86_64/ /usr/local/mysql
# chown -R mysql.mysql /usr/local/mysql*
设置环境变量
# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
# source /etc/profile
创建数据目录
# mkdir -p /data/mysql/3306/data
# mkdir -p /data/mysql/3306/binlog
# chown -R mysql:mysql /data/mysql
# chmod -R 750 /data/mysql
初始化数据库
# mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --user=mysql
官方建议的:初始化完成之后,会生成临时密码
并且开启安全策略(密码长度、密码过期时间180天、密码复杂度)
# mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --user=mysql
不设置密码
编辑配置文件
# vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/3306/data
socket=/tmp/mysql.sock
log_error=/data/mysql/3306/data/mysql.err
user=mysql
[mysql]
socket=/tmp/mysql.sock
配置自启动
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig mysqld on
# service mysqld start
登录mysql并修改root用户密码
# mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'manager';
创建远程用户
mysql> grant all privileges on *.* to 'root'@'192.168.10.1' identified by 'manager';
mysql> flush privileges;
mysql> select user,host from mysql.user;
开放防火墙
# firewall-cmd --permanent --zone=public --add-port=3306/tcp
# firewall-cmd --reload
# firewall-cmd --list-all