yum在线安装,前提是要连网,可以根据ping www.baidu.com来查看是否连网
先下载 MySQL Yum Repository
wget -c https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm
添加 MySQL Yum Repository
yum localinstall mysql80-community-release-el7-5.noarch.rpm
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
验证
yum repolist enabled | grep mysql
MySQL 5.7 Community Server就是我们要下载的版本
在线安装
yum install mysql-community-server
网络原因,下载可能有点慢
启动数据库,查看状态
systemctl enable --now mysqld
systemctl status mysqld
此方法适用于离线安装
进入MySQL的官网https://www.mysql.com/
选择要下载的版本和相对的系统版本
下载RPM安装包
用tar命令解压查看
tar xf mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
ls -l mysql-community*
mysql-community-client 客户端
mysql-community-devel 开发库
mysql-community-common 服务端和客户端的公共文件
mysql-community-embedded 嵌入式
mysql-community-serve 服务端
mysql-community-test 测试组件
mysql-community-libs 共享库
mysql-community-libs-compat MySQL之前版本的共享兼容库
安装
首先要限制mariadb相关软件包,不然会下载不成功,相当于一山不容二虎,不能同时存在
yum remove mariadb-libs
用rpm安装
rpm -ivh mysql-community-client-5.7.14-1.el7.x86_64.rpm mysql-community-common-5.7.14 1.el7.x86_64.rpm mysql-community-libs-5.7.14-1.el7.x86_64.rpm mysql-community-server 5.7.14-1.el7.x86_64.rpm
启动MySQL
systemctl start mysqld
systemctl enable mysqld
新建用户以安全方式运行进程
groupadd -r mysql
useradd -g -r mysql -s /bin/false mysql
tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar -C /usr/local/
安装并初始化mysql
将压缩包软链接成“mysql”方便操作
[root@localhost ~]# cd /usr/local/
[root@localhost local]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
[root@localhost local]# ln -sv mysql-5.7.14-linux-glibc2.5-x86_64 mysql
"mysql" -> "mysql-5.7.14-linux-glibc2.5-x86_64"
[root@localhost local]# chown -R mysql.mysql mysql/*
初始化
mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
为mysql提供服务脚本
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
[root@localhost ~]# vim /etc/init.d/mysql.server
basedir= /usr/local/mysql
datadir =/data/mysql
修改mariadb配置文件
vim /etc/my.cnf
启动MySQL
chkconfig --add mysqld --添加为系统服务
chkconfig mysqld on --开机自启动
systemctl start mysqld
方法一:
[root@localhost ~]# systemctl enable --now mysqld
[root@localhost ~]# grep password /var/log/mysqld.log
[root@localhost~]#tmp_pwd=`awk'/temporary/{print$NF}'/var/log/mysqld.log`
[root@localhost ~]# mysql -uroot -p$tmp_pwd
[root@localhost ~]# mysqladmin -uroot -p$tmp_pwd password 'newpassword'
方法二:
mysqladmin -uroot -p password