您现在的位置是:首页 > 正文

CentOS7安装MySQL

2024-01-30 19:35:26阅读 2

MySQL的下载地址:https://dev.mysql.com/downloads/mysql/

1.由于企业版的要收费,这里就下载社区版的MySQL

1-1.按红圈的下载 

2.下载完成后,上传到服务器

[root@node1 ~]# rz                               #上传文件

[root@node1 ~]# ls                               #查看当前的文件
anaconda-ks.cfg  mysql-community-server-8.0.16-2.el7.x86_64.rpm

3.安装Mysql文件

[root@node1 ~]# yum install mysql-community-server-8.0.16-2.el7.x86_64.rpm 

...
错误:软件包:mysql-community-server-8.0.16-2.el7.x86_64 (/mysql-community-server-8.0.16-2.el7.x86_64)
          需要:mysql-community-client(x86-64) >= 8.0.11
错误:软件包:mysql-community-server-8.0.16-2.el7.x86_64 (/mysql-community-server-8.0.16-2.el7.x86_64)
          需要:mysql-community-common(x86-64) = 8.0.16-2.el7
...


3-1.安装出错了需要 mysql-community-client和mysql-community-common包

 3-2.下载 mysql-community-client和mysql-community-common包后,安装

[root@node1 ~]# rz

[root@node1 ~]# ls
anaconda-ks.cfg                                 mysql-community-common-8.0.16-2.el7.x86_64.rpm
mysql-community-client-8.0.16-2.el7.x86_64.rpm  mysql-community-server-8.0.16-2.el7.x86_64.rpm
[root@node1 ~]# yum install mysql-community-common-8.0.16-2.el7.x86_64.rpm \
> mysql-community-client-8.0.16-2.el7.x86_64.rpm

...
错误:软件包:mysql-community-client-8.0.16-2.el7.x86_64 (/mysql-community-client-8.0.16-2.el7.x86_64)
          需要:mysql-community-libs(x86-64) >= 8.0.11
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest
...

3-3.安装出现错误 了需要mysql-community-libs包

3-4.下载mysql-community-libs包后,安装

[root@node1 ~]# rz

[root@node1 ~]# ls
anaconda-ks.cfg                                 mysql-community-libs-8.0.16-2.el7.x86_64.rpm
mysql-community-client-8.0.16-2.el7.x86_64.rpm  mysql-community-server-8.0.16-2.el7.x86_64.rpm
mysql-community-common-8.0.16-2.el7.x86_64.rpm

 

[root@node1 ~]# yum install mysql-community-libs-8.0.16-2.el7.x86_64.rpm \
> mysql-community-common-8.0.16-2.el7.x86_64.rpm \
> mysql-community-client-8.0.16-2.el7.x86_64.rpm 

...
错误:软件包:2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
          需要:libmysqlclient.so.18(libmysqlclient_18)(64bit)
          正在删除: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@anaconda)
              libmysqlclient.so.18(libmysqlclient_18)(64bit)
          取代,由: mysql-community-libs-8.0.16-2.el7.x86_64 (/mysql-community-libs-8.0.16-2.el7.x86_64)
              未找到
错误:软件包:2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
          需要:libmysqlclient.so.18()(64bit)
          正在删除: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@anaconda)
              libmysqlclient.so.18()(64bit)
          取代,由: mysql-community-libs-8.0.16-2.el7.x86_64 (/mysql-community-libs-8.0.16-2.el7.x86_64)
             ~libmysqlclient.so.21()(64bit)
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest
...

3-5.出现了错误,要卸载mariadb的依赖包

[root@node1 ~]# yum remove maradb*
...
删除:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                        

作为依赖被删除:
  postfix.x86_64 2:2.10.1-6.el7     
[root@node1 ~]# yum install mysql-community-libs-8.0.16-2.el7.x86_64.rpm mysql-community-common-8.0.16-2.el7.x86_64.rpm mysql-community-client-8.0.16-2.el7.x86_64.rpm 

...
已安装:
  mysql-community-client.x86_64 0:8.0.16-2.el7         mysql-community-common.x86_64 0:8.0.16-2.el7        
  mysql-community-libs.x86_64 0:8.0.16-2.el7          

完毕!

3-6.依赖包解决完成后就安装 mysql-community-server-8.0.16-2.el7.x86_64.rpm 包

[root@node1 ~]# yun mysql-community-server-8.0.16-2.el7.x86_64.rpm 
...
已安装:
  mysql-community-server.x86_64 0:8.0.16-2.el7                                                 

完毕!

4. 为了解决更快下载MySQL的依赖包,就要用到清华大学镜像,地址:https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/

4-1.配置清华大学yum 

[root@node1 ~]# vi /etc/yum.repos.d/local.repo 

#centos是本地yum

[cnetos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1

#mysql是清华大学yum

[mysql]
name=mysql
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/
gpgcheck=0
enabled=1

4-2.为了实验的效果,就用强力删除模式,卸载之前安装的MySQL

[root@node1 ~]# rpm -e --nodeps mysql-community-server
[root@node1 ~]# rpm -e --nodeps mysql-community-libs
[root@node1 ~]# rpm -e --nodeps mysql-community-client
[root@node1 ~]# rpm -e --nodeps  mysql-community-common

4-3.重新安装 MySQL

[root@node1 ~]# yum install mysql
...
依赖关系解决

=============================================================================================================================================
 Package                                      架构                         版本                                源                           大
=============================================================================================================================================
正在安装:
 mysql-community-client                       x86_64                       8.0.16-2.el7                        mysql                        3
为依赖而安装:
 mysql-community-common                       x86_64                       8.0.16-2.el7                        mysql                       57
 mysql-community-libs                         x86_64                       8.0.16-2.el7                        mysql                       3.

事务概要
=============================================================================================================================================
安装  1 软件包 (+2 依赖软件包)

总下载量:35 M
安装大小:35 M
Is this ok [y/d/N]: y
...


[root@node1 ~]# yum install mysql-server
...
依赖关系解决

=============================================================================================================================================
 Package                                      架构                         版本                                源                           大
=============================================================================================================================================
正在安装:
 mysql-community-server                       x86_64                       8.0.16-2.el7                        mysql                       40

事务概要
=============================================================================================================================================
安装  1 软件包

总下载量:403 M
安装大小:403 M
Is this ok [y/d/N]: y
...

 5.赋予MySQL存放目录的权限,初始化MySQL,启动MySQL服务和修改MySQL密码

[root@node1 ~]# chown mysql:mysql -R /var/lib/mysql            #赋予mysql存放目录的用户权限和所属用户组的权限


[root@node1 ~]# mysqld --initialize               #mysql初始化


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


[root@node1 ~]# systemctl status mysqld            #查看服务状态
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2019-06-29 21:28:28 CST; 7s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2264 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2289 (mysqld)
   Status: "SERVER_OPERATING"
   CGroup: /system.slice/mysqld.service
           └─2289 /usr/sbin/mysqld

6月 29 21:28:26 node1 systemd[1]: Starting MySQL Server...
6月 29 21:28:28 node1 systemd[1]: Started MySQL Server.

[root@node1 ~]# mysqladmin --version                #查看版本信息
mysqladmin  Ver 8.0.16 for Linux on x86_64 (MySQL Community Server - GPL)



[root@node1 ~]# netstat -antp  | grep mysqld            #查看服务进程和端口
tcp6       0      0 :::33060                :::*                    LISTEN      2289/mysqld         
tcp6       0      0 :::3306                 :::*                    LISTEN      2289/mysqld         


6.连接数据库出错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@node1 ~]#  grep 'temporary password' /var/log/mysqld.log   #查看临时MySQL的密码,数据库会临时产生数据库的密码
2019-07-02T04:25:20.854439Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: !ShW=A4eJskC


[root@node1 ~]# mysql -u root -p                            #连root用户的接数据库,并输入密码
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

6-1.根据官方文档:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-rpm.html

 6-2.在经过反复的查找中发现了:/var/lib/mysql的目录权限为751

[root@node1 ~# ls -lh /var/lib | grep mysql
drwxr-x--x  6 mysql   mysql   4.0K 7月   2 13:42 mysql
drwxr-x---  2 mysql   mysql      6 5月   3 05:11 mysql-files
drwxr-x---  2 mysql   mysql      6 5月   3 05:11 mysql-keyring

 6-3.需要修改/var/lib/mysql的目录权限,为默认目录权限755

[root@node1 ~]# chmod -R 755 /var/lib/mysql

[root@node1 ~]# systemctl restart mysqld

[root@node1 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

7.为MySQL数据库设置自定义密码

[root@node1 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

#翻译一下:在执行此语句之前,必须使用ALTER USER语句重置密码。

7-1.重置密码

mysql> alter user 'root'@'localhost' identified by 'qwe123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

翻译一下:您的密码不满足当前策略的要求

7-2.到官方文档查找一下密码的注意事项,官方地址:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-rpm.html

mysql> alter user 'root'@'localhost' identified by 'Qwe123456.';
Query OK, 0 rows affected (0.01 sec)

8.测实密码的是否重置成功

[root@node1 ~]# mysql -u root -pQwe123456.
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
mysql> 

 参考菜鸟:https://www.runoob.com/mysql/mysql-install.html

 

 

 

 

 

 

网站文章

  • Set对象

    Set对象

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects 可查看网站 Set对象允许你存储任何类型的唯一值,无论是原始值或者是对象引用。 set对象中有很多的方法 1、Set.prototype.add() add()方法用来向一个Set对象的末尾添加一个指定的值。 var...

    2024-01-30 19:35:20
  • APK调试

    APK调试

    源码的情况下,对APK的动态调试主要分为两种:smali汇编动态调试arm汇编动态调试Smali汇编动态调试对smali汇编的动态调试主要分为两种:使用ida进行调试使用IDE + apktool进行调试Eclipse + apktoolAndroid studio + apktoolIdea + apktool…使用jeb2.2以后版本调试IDA 调试smali...

    2024-01-30 19:35:13
  • 使用SourceMonitor完成静态测试

    使用SourceMonitor完成静态测试

    摘要:软件测试作为软件开发中的重要环节,其重要程度不言而喻,从需求定制到软件交付,不仅要保证软件在功能上的要求,同时也要满足性能需求。毕竟,客户体验才是软件赖以生存的基石。本篇文章主要讲述了如何使用SourceMonitor这款软件完成最基本的静态测试,整个流程比较简单。一、软件安装由于本次实验是基于SourceMonitor这款软件完成的,所以需要先下载相应的安装包,网上搜...

    2024-01-30 19:35:05
  • 南艺附中 计算机音乐,南京艺术学院2018年音乐类本科招生考试科目及内容

    南京艺术学院2018年音乐类本科招生考试科目及内容考试科目及内容招生专业及方向考试科目、内容音乐表演(声乐演唱)初试:①演唱(自选歌曲1首)②面试复试:①演唱(自选歌曲2首,曲目不同于初试)②基本乐理...

    2024-01-30 19:34:38
  • Toad for Oracle工具的使用(二)

    Toad for Oracle工具的使用(二)

    脚本管理器 (Script manager): 通过Script Manager,可以对常用的SQL 脚本进行集中管理。还可以做如下工作:

    2024-01-30 19:34:30
  • 翻转棋

    翻转棋

    广搜的问题,重点是位运算的应用。每翻转一个状态就对应一个16位的二进制数。翻转一次就是把某个数上下左右四个位置的棋子都翻转,即0->1,1->0。 Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26891 Accepted: 11647

    2024-01-30 19:34:22
  • Linux下Shell实现当文件大于某size时候删除功能

    Linux下Shell实现当文件大于某size时候删除功能

    2024-01-30 19:33:50
  • c++实现八数码游戏

    c++实现八数码游戏 #include #include #include #include #include #include #include #include #include #include #in

    2024-01-30 19:33:43
  • centos7安装tesseract 4.1.1

    安装leptonicawget http://www.leptonica.org/source/leptonica-1.78.0.tar.gztar -xzvf leptonica-1.78.0.ta...

    2024-01-30 19:33:36
  • 通过 API 远程管理 Jenkins

    背景介绍 最近接到一个需求,需要对公司内部的Android性能测试平台的分支管理模块进行改造。 为了更好地说明问题,在下图中展示了一个精简的持续集成测试系统。 在该系统中,Jenkins负责定时检测代...

    2024-01-30 19:33:07