MySQL yum 在线与本地包方式安装

 以下实践操作是在 liux-centos7 上安装配置

先检测是否安装mysql,然后在拆卸mysql

# 检测
[root@localhost ~]# yum list installed | grep mysql
# 拆卸
[root@localhost ~]# yum -y remove mysql-libs.x86_64

1、官网下载包

https://dev.mysql.com/downloads/repo/yum/

2、安装yum mysql 仓库

下载地址: https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
[root@localhost ~]# yum install -y https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
#查看yum mysql仓库
[root@localhost ~]# ls /etc/yum.repos.d/ 

2.1、如果想使用本地rpm文件,则修改文件 mysql.community.repo文件

[root@localhost ~]# cat /etc/yum.repos.d/

 [root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo

# 修改配置文件
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7community/el/7/$basearch/ #这里修改成本地文件路径
enabled= # -开启 -关闭
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # 设置成0不用检查

3、查看过滤mysql包

[root@localhost ~]# yum list | grep "mysql-community"

mysql-community-server.x86_64 5.7.-.el7 mysql57-community
mysql-community-client.x86_64 5.7.-.el7 mysql57-community

4、安装服务端和客户端

[root@localhost ~]# yum install mysql-community-client mysql-community-server -y

yum install mysql-community-server 

5、启动mysql服务 、查看服务、重启服务器

#启动服务
[root@localhost ~]# systemctl start mysqld

 #查看服务

 [root@localhost ~]# systemctl status mysqld

mysqld.service - MySQL Server
  Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
  Active: active (running) since 三 2019-01-02 20:13:46 CST; 18s ago   #running 开启
  Docs: man:mysqld(8)
  http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 8711 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 8632 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
  Main PID: 8714 (mysqld)
  Tasks: 27
  CGroup: /system.slice/mysqld.service
   └─8714 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

#重启服务

[root@localhost ~]# systemctl restart mysqld

6、登录mysql

#查看密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
[root@localhost ~]# mysql -uroot -p
Enter password:

7、关闭密码策略以及修改密码 ;详细参考:https://www.cnblogs.com/zhi-leaf/p/5994478.html

[root@localhost ~]# set global validate_password_policy=0;
[root@localhost ~]# set global validate_password_length=1;
[root@localhost ~]# ALTER USER 'root'@'localhost' IDENTIFIED BY '';

8、重启服务并登录

[root@localhost ~]# systemctl restart mysqld

[root@localhost ~]# mysql -uroot -p

 Enter password:

9、授权远程登录并刷新权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_root_password' WITH GRANT OPTION;  
FLUSH PRIVILEGES; 

10、关闭防火墙 或者 添加3306端口 以下是关闭防火墙方式

[root@localhost ~]# systemctl stop firewalld                  #关闭当前防火墙
[root@localhost ~]# systemctl disable firewalld #开机自动关闭

11、默认配置文件路径:

配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

 #(a)数据库目录 
   /var/lib/mysql/

 #(b)配置文件
  /usr/share /mysql(mysql.server命令及配置文件)

 #(c)相关命令 
  /usr/bin(mysqladmin mysqldump等命令)

 #(d)启动脚本 
  /etc/rc.d/init.d/(启动脚本文件mysql的目录)

如果忘记root密码,则按如下操作恢复

#在[mysqld]的段中加上一句:skip-grant-tables 保存并且退出vi。

mysql  -u root

update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';

flush privileges

如此文对你有帮助,请打赏作者或推荐此文,在此多谢了~

MySQL yum 在线与本地包方式安装      MySQL yum 在线与本地包方式安装

上一篇:九度OJ1081


下一篇:Cobbler全自动批量安装部署Linux系统