MySQL二进制安装
系统环境:CentOS7
MySQL版本:5.7.38
MySQL下载地址:https://dev.mysql.com/downloads/mysql/
1、前期准备
(1) 创建软件包目录
mkdir /Package # 创建存放软件包目录 yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim net-tools lrzsz unzip tree nmap tree dos2unix nc telnet lsof ntpdate bash-completion bash-completion-extras -y # 安装常用小软件
(2) 卸载自带数据库MariaDB
rpm -qa|grep mariadb # 查找软件包 rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps # 卸载软件保留依赖 rpm -qa|grep mariadb # 查看是否卸载成功
2、上传二进制包到服务器
wget -P /Package https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
3、解压MySQL压缩文件
cd /Package tar -zxvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ cd /usr/local/ mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql5.7.38
4、创建MySQL用户
useradd -s /sbin/nologin mysql
5、设置环境变量
sed -i '$a\export PATH=/usr/local/mysql5.7.38/bin:$PATH' /etc/profile source /etc/profile mysql -V
6、创建数据目录并授权
mkdir -p /data/mysql/data chown -R mysql.mysql /usr/local/mysql5.7.38/* chown -R mysql.mysql /data/mysql
7、初始化数据
mysqld --initialize --user=mysql --basedir=/usr/local/mysql5.7.38 --datadir=/data/mysql/data
扩展:无限制,无临时密码 \rm -rf /data/mysql/data/* mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql5.7.38 --datadir=/data/mysql/data
8、准备配置文件
cat >/etc/my.cnf <<EOF [mysqld] user=mysql basedir=/usr/local/mysql5.7.38 datadir=/data/mysql/data socket=/tmp/mysql.sock server_id=1 port=3306 [mysql] socket=/tmp/mysql.sock EOF
9、启动数据库
(1) sys-v
ln /usr/local/mysql5.7.38/support-files/mysql.server /etc/init.d/mysqld service mysqld start
(2) systemd
cat >/etc/systemd/system/mysqld.service <<EOF [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql5.7.38/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 EOF 注意: sys-v方式启动过的话,需要先提前关闭,才能以下方式登录
10、管理员密码设定 (root@localhost)
mysqladmin -uroot -p password root
输入原密码修改新密码