本文主要是介绍cento7安装mysql详细步骤,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Step1. Mysql
1. 下载安装包
## URL:https://downloads.mysql.com/archives/community/
## 下载后文件为:mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
2. 检测是否安装mariadb和mysql
rpm -qa | grep mariadb
rpm -qa | grep mysql
## 如果有卸载
yum remove mariadb-xxx
3. 解压文件,修改目录名方便配置
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /opt/mysql
cd /opt/mysql
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28
4. 在/usr/local/目录下创建到/opt/mysql-5.7.28的软链接
cd /usr/local
ln -s /opt/mysql/mysql-5.7.28 mysql
5. 添加mysql用户,修改mysql目录权限,并用此用户执行应用
useradd -s /bin/false -M mysql
cd /opt/mysql
chown -R mysql:mysql mysql-5.7.28
6. 在/etc/下创建my.cnf配置文件
[mysqld]
# binlog 配置
log-bin=/usr/local/mysql/logs/mysql-bin.log
expire-logs-days=14
max-binlog-size=500M
server-id=1
# GENERAL
basedir=/opt/mysql/mysql-5.7.28
## 数据存放路径
datadir=/data/appdata/mysqldata
socket=/usr/local/mysql/mysql.sock
user=mysql
default-storage-engine=InnoDB
character-set-server=utf8
lower_case_table_names = 1
explicit_defaults_for_timestamp=true
[mysqld_safe]
log-error=/usr/local/mysql/mysql-error.log
pid-file=/usr/local/mysql/mysqld.pid
[client]
socket=/usr/local/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
7. 创建文件
## 在/usr/local/mysql/创建logs文件
cd /usr/local/mysql/
mkdir logs
chown -R mysql:mysql logscd /opt/mysql/mysql-5.7.28
touch mysql-error.log
chown mysql:mysql mysql-error.log
8. 安装mysql
cd /opt/mysql/mysql-5.7.28
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/appdata/mysqldata
## 如果出现错误
yum -y install autoconf
9. 保存密码
10. 拷贝启动程序,将mysql的启动程序拷贝到/etc/init.d/目录下
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
11. 启动mysql服务
service mysqld start
12. 配置环境变量
vim /etc/profile最后一行追加
#mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile
13. 开机自启
vi /etc/rc.local## 追加一行
systemctl start mysqld.service
这篇关于cento7安装mysql详细步骤的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!