操作系统:CentOS7
安装版本:mysql5.7
【官网】https://dev.mysql.com/downloads/mysql/
一、安装准备
1)查看是否有旧版本MySql,有就逐个删除,避免冲突
rpm -qa | grep mysql
#rpm -e mysql.rpm --nodeps #--nodeps 此处为不验证依赖删除,非必带
2)清除yum里所有mysql依赖包
yum remove mysql-libs #个别是 mariadb-libs——yum remove mariadb-libs
3)查看是否有安装libaio,没有则安装
rpm -qa | grep libaio
#yum -y install libaio #没有则安装
二、下载解压安装
1)下载mysql5.7全家桶
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
2)解压mysql5.7全家桶
tar -xvf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
3)按照依赖关系依次安装rpm包,依赖关系依次为common→libs→client→server
rpm -ivh mysql-community-common-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.32-1.el7.x86_64.rpm
# 可能会出现的报错
error: Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.32-1.el7.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.32-1.el7.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.32-1.el7.x86_64
# 需要安装 numactl
yum install numactl -y
3.png
三、启动mysql
1)mysql基本操作命令
systemctl start mysqld.service 启动mysql
systemctl status mysqld.service 查看mysql状态
systemctl stop mysqld.service 关闭mysql
查看mysql进程 ps ax | grep mysql
查看3306端口 netstat -anop | grep 3306
2)启动mysql及查看root的mysql原始登录密码
#service mysqld {start|stop|force-quit|restart|reload|status|configtest}
service mysqld start #启动命令
grep 'temporary password' /var/log/mysqld.log
5.png
3)输出命令,用户是root,密码是刚刚查看的那个,成功进入后就安装成功了
mysql -uroot -p
4)在5.6后,mysql内置密码增强机制,低强度密码会报错,需要重新设置密码
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
set password for root@localhost=password('password');
5)授予root用户远程访问权限
#(注意:下面命令开启的IP是 192.168.31.132,如要开启所有的,用%代替IP)
mysql> use mysql;
mysql> grant all privileges on *.* to 'root'@'192.168.31.132' identified by 'password' with grant option;
mysql> flush privileges;
# root 是用户,192.168.31.132是指定IP,%是所有IP,password是root用户远程登录的密码
ps:MySQL8不支持上面远程访问权限配置,MySQL8的请使用以下方法
mysql> use mysql;
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'root'; # 创建用户
mysql> GRANT ALL privileges on *.* to 'root'@'%'; # 赋予权限
mysql> alter user 'root'@'%' identified with mysql_native_password by 'root'; #更新用户密码
mysql> flush privileges; # 刷新权限
网友评论