centos7安装mysql5.7.18完整实用教程(★firecat推荐★)

CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载https://downloads.mysql.com/archives/community/
centos7安装mysql5.7.18完整实用教程(★firecat推荐★)_第1张图片
 

1、准备工作

最简单的安装mysql-server服务,只需要准备好如下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  numactl

error: 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)

 

 

笔者注:远程连接的前提条件,先要关闭Linux的防火墙。

CentOS 7操作防火墙的命令是:

[root@localhost ~]# firewall-cmd --state #查看防火墙是否启用

[root@localhost ~]# systemctl stop firewalld#关闭防火墙

 

mysql-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

 

参考文章:

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

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

 

你可能感兴趣的:(MySQL,Linux)