一、安装

CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载MySQL :: Download MySQL Community Server (Archived Versions)

centos卸载安装包rpm 卸载centos7_centos卸载安装包rpm

 

1、准备工作

我们可以一次性下载一个总的安装包,mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar。解压之后,里面包含了许多小的安装包。

centos卸载安装包rpm 卸载centos7_centos_02

先看看各个安装包分别代表什么功能:

centos卸载安装包rpm 卸载centos7_linux_03

我们不需要所有的包都安装,只需要准备好如下5个软件包即可,

我们可以使用rpm -ivh命令进行安装

mysql-community-common-5.7.18-1.el7.x86_64.rpm
 mysql-community-libs-5.7.18-1.el7.x86_64.rpm             --(依赖于common)
 mysql-community-client-5.7.18-1.el7.x86_64.rpm          --(依赖于libs)
 mysql-community-server-5.7.18-1.el7.x86_64.rpm         --(依赖于client、common)mysql-community-devel-5.7.18-1.el7.x86_64.rpm          -- 里面内容是c语言版本的客户端库函数和头文件
注:c语言客户端默认安装位置是
头文件 /usr/include/mysql
静态和动态库 /usr/lib64/mysql
2、按顺序逐个安装rpm
[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
 warning: mysql-community-common-5.7.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 Preparing...                          ################################# [100%]
 file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.18-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64笔者注:提示库冲突,需要先卸载centos原有的mariadb-libs。请注意,这样会同时卸载掉谷歌浏览器。没关系,先安装完mysql,然后再把谷歌浏览器装回来。
 [root@localhost mysql]# yum remove mysql-libs

笔者注:然后再正式安装,注意先后顺序
 [root@localhost mysql]# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
 warning: mysql-community-common-5.7.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 Preparing...                          ################################# [100%]
 Updating / installing...
    1:mysql-community-common-5.7.18-1.e################################# [100%]

 [root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
 warning: mysql-community-libs-5.7.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 Preparing...                          ################################# [100%]
 Updating / installing...
    1:mysql-community-libs-5.7.18-1.el7################################# [100%]

 [root@localhost mysql]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
 warning: mysql-community-client-5.7.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 Preparing...                          ################################# [100%]
 Updating / installing...
    1:mysql-community-client-5.7.18-1.e################################# [100%]

 [root@localhost mysql]# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm
 warning: mysql-community-server-5.7.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 Preparing...                          ################################# [100%]
 Updating / installing...
    1:mysql-community-server-5.7.18-1.e################################# [100%]
  如果编译报错:
error: Failed dependencies:
     libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.18-1.el7.x86_64
     libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.18-1.el7.x86_64
     libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.18-1.el7.x86_64
 不要紧,安装依赖库numactl即可    
[root@localhost mysql]# yum  install  numactlerror: Failed dependencies:
         net-tools is needed by mysql-community-server-5.7.23-1.el7.x86_64
[root@localhost mysql]# yum install net-tools[root@localhost mysql]# rpm -ivh mysql-community-devel-5.7.18-1.el7.x86_64.rpm
笔者注:启动mysql服务
 [root@localhost ~]# systemctl start mysqld笔者注:查看mysql服务
 [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 Fri 2017-07-28 14:39:49 CST; 13s ago
      Docs: man:mysqld(8)
            http://dev.mysql.com/doc/refman/en/using-systemd.html   Process: 102480 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
   Process: 102401 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
  Main PID: 102482 (mysqld)
    CGroup: /system.slice/mysqld.service
            └─102482 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/m...

 Jul 28 14:39:42 localhost.localdomain systemd[1]: Starting MySQL Server...
 Jul 28 14:39:49 localhost.localdomain systemd[1]: Started MySQL Server.
  笔者注:查看首次安装后,mysql默认生成的root密码
 [root@localhost ~]# cat /var/log/mysqld.log | grep password
 2017-07-28T06:39:45.719457Z 1 [Note] A temporary password is generated for root@localhost:ZkGlpbBH;9s?

笔者注:root登录,输入默认密码。这个默认密码是随机生成的,不同机器不同。
 [root@localhost ~]# mysql -u root -p
 Enter password: ZkGlpbBH;9s?
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 3
 Server version: 5.7.18

 Copyright (c) 2000, 2017, 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> create database helloworld;
 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

笔者注:修改密码,需要大小写字母,数字和字符的组合
 mysql> SET PASSWORD = PASSWORD('Mypwd123456$');
 Query OK, 0 rows affected, 1 warning (0.01 sec)

笔者注:授权远程客户端连接
 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Mypwd123456$' WITH GRANT OPTION;Query OK, 0 rows affected, 1 warning (0.01 sec)
 mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected, 1 warning (0.01 sec)
查看版本
 mysql> select version();退出命令行
 mysql> exit笔者注:远程连接的前提条件,先要关闭Linux的防火墙。
CentOS 7操作防火墙的命令是:
[root@localhost ~]# firewall-cmd --state #查看防火墙是否启用
[root@localhost ~]# systemctl stop firewalld#关闭防火墙
重启mysql
 [root@localhost mysql]# systemctl restart mysqldmysql-community-devel-5.7.18-1.el7.x86_64.rpm安装完毕后,就带了c语言版本的库函数,头文件和库路径分别是/usr/include/mysql和/usr/lib64/mysql
CMakeLists.txt文件:
SET(MYSQL_INCLUDE_DIR /usr/include/mysql)
 SET(MYSQL_LIB /usr/lib64/mysql)INCLUDE_DIRECTORIES(${MYSQL_INCLUDE_DIR})
 LINK_DIRECTORIES(${MYSQL_LIB})TARGET_LINK_LIBRARIES(mysqlclient)
安装完毕后,
数据库文件默认在:cd /usr/share/mysql
 配置文件默认在:/etc/my.cnf
二、卸载
停止mysql的运行
 [root@localhost ~]# systemctl stop mysqld查看已经安装的mysql
 [root@localhost ~]# rpm -qa|grep -i mysql
 mysql-community-client-5.7.18-1.el7.x86_64
 mysql-community-server-5.7.18-1.el7.x86_64
 mysql-community-common-5.7.18-1.el7.x86_64
 mysql-community-libs-5.7.18-1.el7.x86_64
 mysql-community-devel-5.7.18-1.el7.x86_64手动逐个逐个删除
 [root@localhost ~]# yum -y remove mysql-community-client-5.7.18-1.el7.x86_64
 [root@localhost ~]# yum -y remove mysql-community-common-5.7.18-1.el7.x86_64
 [root@localhost ~]# yum -y remove mysql-community-server-5.7.18-1.el7.x86_64
 [root@localhost ~]# yum -y remove mysql-community-libs-5.7.18-1.el7.x86_64
 [root@localhost ~]# yum -y remove mysql-community-devel-5.7.18-1.el7.x86_64查看有关mysql的目录
 [root@localhost ~]# find / -name mysql
 /etc/selinux/targeted/active/modules/100/mysql
 /etc/selinux/targeted/tmp/modules/100/mysql
 /root/Downloads/mysql
 /var/lib/mysql
 /var/lib/mysql/mysql
 /usr/share/mysql手动全部删除
 [root@localhost ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql
 [root@localhost ~]# rm -rf /etc/selinux/targeted/tmp/modules/100/mysql
 [root@localhost ~]# rm -rf /root/Downloads/mysql
 [root@localhost ~]# rm -rf /var/lib/mysql
 [root@localhost ~]# rm -rf /var/lib/mysql/mysql
 [root@localhost ~]# rm -rf /usr/share/mysql删除mysql配置文件
 [root@localhost ~]# rm -rf /etc/my.cnf删除mysql默认密码
 [root@localhost ~]# rm -rf /root/.mysql_history
 [root@localhost ~]# rm -rf /root/mysql_secret删除mysql日志
 必须删除这个,否则新安装的mysql无法创建新密码
 [root@localhost ~]# rm -rf /var/log/mysqld.log

 

三、参考文章

centos7安装mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

关于linux-Centos 7下mysql 5.7.9的rpm包的安装方式