一、首先到官网下载吧:
二、解压:
解压后有如下rpm:
[root@hostaa mysql_rpm]# ls -l
总用量 1141908
-rw-r--r-- 1 root root 584652800 5月 13 01:02 mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415 25079412 3月 20 17:40 mysql-community-client-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 277784 3月 20 17:40 mysql-community-common-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 3777808 3月 20 17:40 mysql-community-devel-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 45493312 3月 20 17:40 mysql-community-embedded-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 23924496 3月 20 17:40 mysql-community-embedded-compat-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 126060264 3月 20 17:40 mysql-community-embedded-devel-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2237888 3月 20 17:40 mysql-community-libs-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2113196 3月 20 17:40 mysql-community-libs-compat-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 54661812 3月 20 17:40 mysql-community-minimal-debuginfo-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 169622200 3月 20 17:41 mysql-community-server-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 14501488 3月 20 17:41 mysql-community-server-minimal-5.7.18-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 116887988 3月 20 17:41 mysql-community-test-5.7.18-1.el7.x86_64.rpm
三、一个rpm一个rpm的来安装吧
这里要注意安装顺序,但是其实不用记顺序。
比如我先安装server吧:(如果没有安装common和client就会报错)
#rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.18-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
mysql-community-client(x86-64) >= 5.7.9 被 mysql-community-server-5.7.18-1.el7.x86_64 需要
mysql-community-common(x86-64) = 5.7.18-1.el7 被 mysql-community-server-5.7.18-1.el7.x86_64 需要
有人说可以取消依赖:#rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm --nodeps,但是个人不建议这么做,安装好后可能也会有问题,rpm都有了,依赖检测失败你就装上依赖就是了。
3.1好吧,那就先安装common吧
# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.18-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [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.44-2.el7.centos.x86_64
file /usr/share/mysql/danish/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.44-2.el7.centos.x86_64
... ...
file /usr/share/mysql/estonian/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.44-2.el7.centos.x86_64
file /usr/share/mysql/french/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.44-2.el7.centos.x86_64
... ...
来自mysql-ccommunity-common-5.7.18-1.el7.x86_的文件和mariadb-libs-1:5.5.44-2.el7.centos.x86_64的文件冲突?什么意思?查了下:
出现以上安装错误列表的原因是:系统已经安装了其他版本的mysql-libs包和mysql数据库文件导致不兼容
解决:# yum remove mysql-libs
------------------------------------------------------------------------------------------------------------------------
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.44-2.el7.centos 将被 删除
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在检查事务
---> 软件包 postfix.x86_64.2.2.10.1-6.el7 将被 删除
--> 解决依赖关系完成
base/7/x86_64 | 3.6 kB 00:00:00
extras/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
依赖关系解决
=======================================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================================
正在删除:
mariadb-libs x86_64 1:5.5.44-2.el7.centos @anaconda 4.4 M
为依赖而移除:
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M
事务概要
=======================================================================================================================================
移除 1 软件包 (+1 依赖软件包)
安装大小:17 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
** 发现 4 个已存在的 RPM 数据库问题, 'yum check' 输出如下:
icedtea-web-1.6.1-4.el7.x86_64 有缺少的需求 java-1.8.0-openjdk
jline-1.0-8.el7.noarch 有缺少的需求 java >= ('0', '1.5', None)
1:libreoffice-core-4.3.7.2-5.el7.x86_64 有缺少的需求 java-headless >= ('1', '1.6', None)
1:libreoffice-ure-4.3.7.2-5.el7.x86_64 有缺少的需求 libjvm.so()(64bit)
正在删除 : 2:postfix-2.10.1-6.el7.x86_64 1/2
正在删除 : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 2/2
验证中 : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 1/2
验证中 : 2:postfix-2.10.1-6.el7.x86_64 2/2
删除:
mariadb-libs.x86_64 1:5.5.44-2.el7.centos
作为依赖被删除:
postfix.x86_64 2:2.10.1-6.el7
完毕!
------------------------------------------------------------------------------------------------------------------------------------------------------------
类似的错误,都可以先试试彻底从centos中卸载mysql。
3.2然后再重新安装依次安装吧:
# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.18-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.18-1.e################################# [100%]
# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.18-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.18-1.el7################################# [100%]
# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.18-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.18-1.e################################# [100%]
# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.18-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.18-1.e################################# [100%]
# rpm -ivh mysql-community-devel-5.7.18-1.el7.x86_64.rpm (可选安装)
警告:mysql-community-devel-5.7.18-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-devel-5.7.18-1.el################################# [100%]
四、启动:
# systemctl start mysqld
启动可能会失败,mysql不允许用root用户启动mysql服务,这时可以新建一个用户专门管理和启动mysql服务
查看状态:
# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active:
active (running)since 六 2017-05-13 13:39:56 CST; 28min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 5791 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 5714 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 5795 (mysqld)
CGroup: /system.slice/mysqld.service
└─5795 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
5月 13 13:39:28 hostaa systemd[1]: Starting MySQL Server...
5月 13 13:39:56 hostaa systemd[1]: Started MySQL Server.
5月 13 14:05:49 hostaa systemd[1]: Started MySQL Server.
五、登陆:
这种方式安装好后,会再my.cnf文件中自动生成一个密码,执行看一下吧:
# cat /var/log/mysqld.log | grep password
2017-05-13T05:39:44.497086Z 1 [Note] A temporary password is generated for root@localhost:
pKsO:Jin<4f%
密码就是这么复杂,复制吧,不然手输还容易出错。
登陆:#mysql -u root -p
Enter password:
pKsO:Jin<4f%
Welcome to the MySQL monitor. Commands end with ; or \g
Your MySQL connection id is 7
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>
.--登陆成功,但是这时候,还不能做任何事情。随便你做什么都会提示你:
ERROR 1820 (HY000):
You must reset your password
using ALTER USER statement before executing this statement.
那就来reset吧:
mysql> SET PASSWORD = PASSWORD('Mysql5718');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
(密码过于简单,必须大写,小写,数字,符号)
mysql> SET PASSWORD = PASSWORD('Mysql5718%');
Query OK, 0 rows affected, 1 warning (0.00 sec)
好了,现在终于可以操作了:
mysql> create database roger;
Query OK, 1 row affected (0.01 sec)
mysql> use roger;
Database changed
mysql>
额外:一般自己装个mysql就是用来测试的,结果密码还那么麻烦,哪天忘记了都有可能,想要设置简单的密码,把密码安全级别设置低一点吧:
mysql> set global validate_password_policy=0;//0最低,1中级,2最强验证级别
Query OK, 0 rows affected (0.00 sec)
Policy | Tests Performed |
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
六、授权远程连接:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Mysql5718%' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
这样,我们就可以在其他电脑上的mysql客户端远程连接linux上的mysql数据库了:(例如在win cmd里面)
C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin>mysql -u root -pMysql5718% -h 192.168.231.8 -D roger
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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>
(如果连不上,看看是不是防火墙开着的。)