Centos 7安装Mysql

Centos 7安装Mysql 5.7.22

0.前言
  • 因为Centos 7自带了Mysql的一个小的版本分支(Mriadb),所以如果直接使用rpm包安装的时候,会报lib confilict,即包冲突。所以先将mariadb删除,但是这里就有一个问题,如果mariadb有底层依赖包怎么办?如果删除了mariadb会不会对系统造成影响?这里放心,尽管使用--nodeps命令卸载mariadb。
  • 本文采取的是rpm包安装的方式,如果需要其他方式安装的同学们请绕道。
1.下载mysql的rpm包
2.卸载mariadb数据库
[root@server3 ~]# rpm -qa | grep  mariadb-libs-5.5.56-2.el7.x86_64
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64
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

发现卸载失败,看报错消息可知是有libmysqlclient.so.18()是其它软件的底层依赖包。于是采取一种比较暴力的措施,连依赖一起删除。

3.安装mysql

【安装顺序一定要按照上述列举包的顺序】

[root@server3 ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@server3 ~]# ll
total 199632
-rw-------. 1 root root      1260 Jul 14 18:47 anaconda-ks.cfg
-rw-r--r--. 1 root root  25106088 Jul 14 23:05 mysql-community-client-5.7.22-1.el7.x86_64.rpm
-rw-r--r--. 1 root root    280800 Jul 14 23:02 mysql-community-common-5.7.22-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   3781636 Jul 14 23:02 mysql-community-devel-5.7.22-1.el7.x86_64.rpm
-rw-r--r--. 1 root root   2239868 Jul 14 23:05 mysql-community-libs-5.7.22-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 172992596 Jul 14 23:05 mysql-community-server-5.7.22-1.el7.x86_64.rpm
[root@server3 ~]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.22-1.e################################# [100%]
[root@server3 ~]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.22-1.el7################################# [100%]
[root@server3 ~]# rpm -ivh mysql-community-devel-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-devel-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-devel-5.7.22-1.el################################# [100%]
[root@server3 ~]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.22-1.e################################# [100%]
[root@server3 ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	/usr/bin/perl is needed by mysql-community-server-5.7.22-1.el7.x86_64
	perl(Getopt::Long) is needed by mysql-community-server-5.7.22-1.el7.x86_64
	perl(strict) is needed by mysql-community-server-5.7.22-1.el7.x86_64
[root@server3 ~]# rpm -qa | grep mysql
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-client-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
mysql-community-devel-5.7.22-1.el7.x86_64
[root@server3 ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	/usr/bin/perl is needed by mysql-community-server-5.7.22-1.el7.x86_64
	perl(Getopt::Long) is needed by mysql-community-server-5.7.22-1.el7.x86_64
	perl(strict) is needed by mysql-community-server-5.7.22-1.el7.x86_64

最后安装server时,发现有server需要的perl包依赖没有安装。补上即可。

[root@server3 ~]# rpm -qa | grep perl
[root@server3 ~]# yum install -y  perl 
Loaded plugins: fastestmirror
base                                                                            | 3.6 kB  00:00:00     
extras                                                                          | 3.4 kB  00:00:00     
updates                                                                         | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                   | 166 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                               | 150 kB  00:00:02     
(3/4): updates/7/x86_64/primary_db                                              | 3.6 MB  00:00:07     
(4/4): base/7/x86_64/primary_db                                                 | 5.9 MB  00:00:14     
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package perl.x86_64 4:5.16.3-292.el7 will be installed
·····【省略输出】               
  perl-libs.x86_64 4:5.16.3-292.el7                perl-macros.x86_64 4:5.16.3-292.el7                 
  perl-parent.noarch 1:0.225-244.el7               perl-podlators.noarch 0:2.5.1-3.el7                 
  perl-threads.x86_64 0:1.87-4.el7                 perl-threads-shared.x86_64 0:1.43-6.el7             

Complete!

perl依赖包安装上即可。

[root@server3 ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.22-1.e################################# [100%]
[root@server3 ~]# rpm -qa | grep mysql
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-client-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
mysql-community-devel-5.7.22-1.el7.x86_64
mysql-community-server-5.7.22-1.el7.x86_64

查看已安装的mysql包

4.启动,检查mysql服务
[root@server3 ~]# systemctl start  mysqld.service
[root@server3 ~]# systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-07-14 23:43:57 EDT; 9s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 4179 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 4106 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 4183 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─4183 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/my...

Jul 14 23:43:49 server3 systemd[1]: Starting MySQL Server...
Jul 14 23:43:57 server3 systemd[1]: Started MySQL Server.
[root@server3 ~]# grep "password" /var/log/mysqld.log
2018-07-15T03:43:51.844245Z 1 [Note] A temporary password is generated for root@localhost: *be+sh,p%3pM
[root@server3 ~]# mysql -u root -p*be+sh,p%3pM
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 2
Server version: 5.7.22

Copyright (c) 2000, 2018, 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>
5.配置mysql
  • 修改mysql的root密码
mysql> alter user 'root'@'server3' identified by 'root';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

因为密码设置太过简单报错!

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

mysql> alter user 'root'@'localhost' identified by '3242@#@$1sdfsdN';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

即使使用不规则但复杂的密码仍然会报错,是因为mysql的密码必须设置成 大小写+特殊字符+一定长度等。正是因为如下的validate_password_policy设置成了MEDIUM才导致成了密码验证问题:

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

修改/etc/my.cnf文件,在[mysqld]域下添加validate-password=OFF,然后重启mysql服务

[root@bi_5 ~]# vi /etc/my.cnf
[root@bi_5 ~]# systemctl stop mysqld
[root@bi_5 ~]# systemctl start mysqld
[root@bi_5 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-07-27 14:04:43 CST; 4s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 15258 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 15240 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 15262 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─15262 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jul 27 14:04:42 bi_5.109 systemd[1]: Starting MySQL Server...
Jul 27 14:04:43 bi_5.109 systemd[1]: Started MySQL Server.

[root@bi_5 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

最后登录即可

[root@server3 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> 

至此安装成功!

下面依次列举出安装命令:

rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.22-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 
-------------------------------------20180715更新-----------------------

因为5.7的版本和5.6的版本的依赖包有一些不同,所以当我们在安装一些软件时,【这些软件可能使用的是mysql5.6版本的依赖包编译,但是恰恰mysql5.7版本中不存在】在这种情况下,就会出现依赖包找不到的情况,比如今天我在安装cdh时,报出如下错误:

Error: Package: MySQL-python-1.2.5-1.el7.x86_64 (base)
Requires: libmysqlclient.so.18()(64bit)
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
Requires: libmysqlclient.so.18()(64bit)
Error: Package: MySQL-python-1.2.5-1.el7.x86_64 (base)
Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)	
  • 报错原因:在mysql5.7版本中,缺失这个libmysqlclient.so.18(64bit)这个文件
  • 解决方法:下载mysql提供的兼容包即可,下载链接https://dev.mysql.com/downloads/file/?id=476874。 下载完成之后安装即可解决该问题。
Suggested fix:
Add libmysqlclient.so.18(64bit) to the mysql-community-libs-compat package.
# rpm -qa | grep ^mysql-community
mysql-community-libs-5.7.12-1.el6.x86_64
mysql-community-devel-5.7.12-1.el6.x86_64
mysql-community-common-5.7.12-1.el6.x86_64
mysql-community-client-5.7.12-1.el6.x86_64
mysql-community-libs-compat-5.7.12-1.el6.x86_64
mysql-community-server-5.7.12-1.el6.x86_64
6.参考文章
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

说文科技

看书人不妨赏个酒钱?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值