文章目录
一、准备文件
传送门提取码:ywqc
下载解压后,上传到服务器。
二、检查系统
1、卸载系统自带MySQL。
yum remove mysql-libs
如果跳过这步执行,在安装过程中会有相应的提示,譬如:
# 安装mysql组件时出现的依赖错误
error: Failed dependencies:
mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.19-1.el7.x86_64
mariadb-libs is obsoleted by mysql-community-libs-5.7.19-1.el7.x86_64
# 卸载mariadb-libs时出现的依赖错误
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
可以看出需要我们卸载postfix和mariadb-libs相关的组件,卸载我们可以用rpm -ev xxx。
2、卸载postfix和mariadb-libs
执行下面语句
# rpm -qa | grep postfix
# rpm -qa | grep mariadb
#执行结果
[root@localhost software]# rpm -qa | grep postfix
postfix-2.10.1-6.el7.x86_64
[root@localhost software]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
卸载postfix 和mariadb-libs
rpm -ev postfix-2.10.1-6.el7.x86_64
rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
# 执行结果
[root@localhost software]# rpm -ev postfix-2.10.1-6.el7.x86_64
Preparing packages...
postfix-2:2.10.1-6.el7.x86_64
[root@localhost software]# rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
Preparing packages...
mariadb-libs-1:5.5.52-1.el7.x86_64
三、安装
安装过程中是有顺序要求的,基本原则:common(共用)——>libs(依赖)——>client(客户端)——>server(服务端)
rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm
四、配置
1、登录
在vi /etc/my.cnf里 加入 skip-grant-tables
vim /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip-grant-tables
在配置文件中加入skip-grant-tables,就可以无密码登陆mysql
skip-grant-tables
修改后保存,重启mysql服务
systemctl mysqld restart
或
service mysqld restart
2、修改密码
登陆之后,可以先使用 show databases 看下mysql是否安装正确
先修改密码:
update user set authentication_string=password('123456') where user="root";
退出,将之前的skip-grant-tables删掉 或注释掉,再登陆
mysql –u root –p
—>输入密码
然后
本地登录密码设置
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;
注:如果密码设置为“123456”的话,可能会提示太简单,错误信息如下:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
可以先修改密码规则:
set global validate_password_policy=0;
set global validate_password_length=1;
3、远程密码登录
use mysql;
grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges;
4、打开端口(设置防火墙)
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
5、添加字符集
在/etc/my.cnf 文件f 文件 [mysqld]下面添加:
character-set-server = utf8
collation-server = utf8_general_ci
重启
systemctl mysqld restart
五、测试
mysql -u root -h -h 主机地址 -p -p 密码
show variables like ‘character%’