一、清理环境
1、检查是否已经安装过mysql,执行命令
rpm -qa | grep mysql
如果查出来有安装包,使用如下命令清理
rpm -e --nodeps `rpm -qa | grep mysql`
再次执行查询命令,查看是否删除
2、查询所有Mysql对应的文件夹
whereis mysql
mysql: /usr/bin/mysql /usr/include/mysql
find / -name mysql
/data/mysql
/data/mysql/mysql
删除相关目录或文件
rm -rf /usr/bin/mysql /usr/include/mysql /data/mysql /data/mysql/mysql
验证是否删除完毕
whereis mysql
find / -name mysql
3、检查mysql用户组和用户是否存在,如果没有,则创建
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
groupadd mysql
useradd -s /sbin/nologin -M mysql
二、安装部署mysql-5.7
1.创建mysql目录
mkdir /root/soft
cd /root/soft
2.下载安装包并解压
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
tar -xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
3.移动到指定目录下并更名
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql
4.安装mysql5.7的依赖包
yum install -y libaio-devel numactl
5.设置环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
mysql -V
mysql Ver 14.14 Distrib 5.7.43, for Linux (x86_64) using EditLine wrapper
6.创建数据目录,并授权
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/logs
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
7.编译安装并初始化mysql
cd /usr/local/mysql/bin
./mysqld --initialize-insecure --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
8.编辑配置文件my.cnf,添加配置如下
cat >/etc/my.cnf <<'EOF'
[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql # 应用目录
datadir=/usr/local/mysql/data # 数据目录
socket=/usr/local/mysql/mysql.sock # socket文件目录
server-id=100 # 主机id,必须要区别于其他机器
log_bin=/usr/local/mysql/logs/mysql-bin # binlog日志目录
character_set_server=utf8mb4 # 设置全局字符为utf8mb4
[mysql]
socket=/usr/local/mysql/mysql.sock
EOF
三、启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
启动服务
systemctl enable mysqld
systemctl restart mysqld
systemctl status mysqld
如果想前台启动
mysqld_safe --defaults-file=/etc/my.cnf
四、登录mysql,修改密码
mysql
>set password for root@localhost = password('yourpass');
Query OK, 0 rows affected, 1 warning (0.00 sec)
五、开放远程连接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
标签:部署,etc,mysqld,usr,mysql,--,local
From: https://www.cnblogs.com/chunjeh/p/17785931.html