当前位置: 移动技术网 > IT编程>数据库>Mysql > centos7.3 安装mysql5.7.18的详细教程

centos7.3 安装mysql5.7.18的详细教程

2017年12月07日  | 移动技术网IT编程  | 我要评论

廖汉生,粘胶,长虹手机qq下载

1查看linux发行版本

[root@typecodes ~]# cat /etc/redhat-release
centos linux release 7.2.1511 (core)

2 下载mysql官方的yum repository

根据linux发行版本(centos、fedora都属于红帽系),从mysql官方()获取yum repository。

[root@typecodes ~]# wget -i http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
--2016-02-03 18:36:02-- http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
http request sent, awaiting response... 302 found
location: http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm [following]
--2016-02-03 18:36:04-- http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
resolving repo.mysql.com (repo.mysql.com)... 104.102.164.25
connecting to repo.mysql.com (repo.mysql.com)|104.102.164.25|:80... connected.
http request sent, awaiting response... 200 ok
length: 8984 (8.8k) [application/x-redhat-package-manager]
saving to: ‘mysql57-community-release-el7-7.noarch.rpm'
100%[=============================================================================================================================>] 8,984  --.-k/s in 0s
2016-02-03 18:36:07 (68.4 mb/s) - ‘mysql57-community-release-el7-7.noarch.rpm' saved [8984/8984]
3 安装mysql的yum repository
安装完mysql的yum repository,每次执行yum update都会检查mysql是否更新。
[root@typecodes ~]# yum -y install mysql57-community-release-el7-7.noarch.rpm
loaded plugins: axelget, fastestmirror, langpacks
examining mysql57-community-release-el7-7.noarch.rpm: mysql57-community-release-el7-7.noarch
marking mysql57-community-release-el7-7.noarch.rpm to be installed
resolving dependencies
--> running transaction check
---> package mysql57-community-release.noarch 0:el7-7 will be installed
--> finished dependency resolution
dependencies resolved
=======================================================================================================================================================================
 package          arch      version     repository             size
=======================================================================================================================================================================
installing:
 mysql57-community-release      noarch      el7-7      /mysql57-community-release-el7-7.noarch      7.8 k
transaction summary
=======================================================================================================================================================================
install 1 package
total size: 7.8 k
installed size: 7.8 k
downloading packages:
running transaction check
running transaction test
transaction test succeeded
running transaction
 installing : mysql57-community-release-el7-7.noarch                            1/1 
 verifying : mysql57-community-release-el7-7.noarch                           1/1
installed:
 mysql57-community-release.noarch 0:el7-7
complete!

3 安装mysql数据库的服务器版本

[root@typecodes ~]# yum -y install mysql-community-server
loaded plugins: axelget, fastestmirror, langpacks
no metadata available for base
no metadata available for epel
no metadata available for extras
repomd.xml                                  | 2.5 kb 00:00:00  
update mysql-connectors-community metadata successfully
repomd.xml                                  | 2.5 kb 00:00:00  
update mysql-tools-community metadata successfully
repomd.xml                                  | 2.5 kb 00:00:00  
update mysql57-community metadata successfully
no metadata available for updates
mysql-connectors-community                              | 2.5 kb 00:00:00  
mysql-tools-community                               | 2.5 kb 00:00:00  
mysql57-community                                | 2.5 kb 00:00:00  
(1/3): mysql-tools-community/x86_64/primary_db                         | 24 kb 00:00:01  
(2/3): mysql57-community/x86_64/primary_db                          | 28 kb 00:00:01  
(3/3): mysql-connectors-community/x86_64/primary_db                        | 8.6 kb 00:00:02  
loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.neusoft.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.163.com
resolving dependencies
--> running transaction check
---> package mysql-community-server.x86_64 0:5.7.10-1.el7 will be installed
--> processing dependency: mysql-community-common(x86-64) = 5.7.10-1.el7 for package: mysql-community-server-5.7.10-1.el7.x86_64
--> processing dependency: mysql-community-client(x86-64) = 5.7.10-1.el7 for package: mysql-community-server-5.7.10-1.el7.x86_64
--> running transaction check
---> package mysql-community-client.x86_64 0:5.7.10-1.el7 will be installed
--> processing dependency: mysql-community-libs(x86-64) = 5.7.10-1.el7 for package: mysql-community-client-5.7.10-1.el7.x86_64
---> package mysql-community-common.x86_64 0:5.7.10-1.el7 will be installed
--> running transaction check
---> package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be obsoleted
--> processing dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> processing dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> package mysql-community-libs.x86_64 0:5.7.10-1.el7 will be obsoleting
--> running transaction check
---> package mysql-community-libs-compat.x86_64 0:5.7.10-1.el7 will be obsoleting
--> finished dependency resolution
dependencies resolved
=======================================================================================================================================================================
 package           arch       version        repository        size
=======================================================================================================================================================================
installing:
 mysql-community-libs        x86_64      5.7.10-1.el7       mysql57-community      2.2 m
  replacing mariadb-libs.x86_64 1:5.5.44-2.el7.centos
 mysql-community-libs-compat      x86_64      5.7.10-1.el7       mysql57-community      2.0 m
  replacing mariadb-libs.x86_64 1:5.5.44-2.el7.centos
 mysql-community-server        x86_64      5.7.10-1.el7       mysql57-community      142 m
installing for dependencies:
 mysql-community-client        x86_64      5.7.10-1.el7       mysql57-community       24 m
 mysql-community-common        x86_64      5.7.10-1.el7       mysql57-community      269 k
transaction summary
=======================================================================================================================================================================
install 3 packages (+2 dependent packages)
total download size: 171 m
downloading packages:
mysql-community-server-5.7.10-1.el7.x86_64.rpm                         | 142 mb 00:03:42  
mysql-community-libs-compat-5.7.10-1.el7.x86_64.rpm                        | 2.0 mb 00:00:03  
mysql-community-libs-5.7.10-1.el7.x86_64.rpm                         | 2.2 mb 00:00:05  
mysql-community-client-5.7.10-1.el7.x86_64.rpm                         | 24 mb 00:00:41  
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.10-1.el7.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey00 eta 
public key for mysql-community-common-5.7.10-1.el7.x86_64.rpm is not installed
mysql-community-common-5.7.10-1.el7.x86_64.rpm                         | 269 kb 00:00:01  
retrieving key from file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql
importing gpg key 0x5072e1f5:
 userid  : "mysql release engineering <mysql-build@oss.oracle.com>"
 fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 package : mysql57-community-release-el7-7.noarch (@/mysql57-community-release-el7-7.noarch)
 from  : /etc/pki/rpm-gpg/rpm-gpg-key-mysql
running transaction check
running transaction test
transaction test succeeded
running transaction
 installing : mysql-community-common-5.7.10-1.el7.x86_64                           1/6 
 installing : mysql-community-libs-5.7.10-1.el7.x86_64                           2/6 
 installing : mysql-community-client-5.7.10-1.el7.x86_64                           3/6 
 installing : mysql-community-server-5.7.10-1.el7.x86_64                           4/6 
 installing : mysql-community-libs-compat-5.7.10-1.el7.x86_64                          5/6 
 erasing : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                           6/6 
 verifying : mysql-community-server-5.7.10-1.el7.x86_64                           1/6 
 verifying : mysql-community-libs-compat-5.7.10-1.el7.x86_64                          2/6 
 verifying : mysql-community-common-5.7.10-1.el7.x86_64                           3/6 
 verifying : mysql-community-libs-5.7.10-1.el7.x86_64                           4/6 
 verifying : mysql-community-client-5.7.10-1.el7.x86_64                           5/6 
 verifying : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                           6/6
installed:
 mysql-community-libs.x86_64 0:5.7.10-1.el7   mysql-community-libs-compat.x86_64 0:5.7.10-1.el7   mysql-community-server.x86_64 0:5.7.10-1.el7
dependency installed:
 mysql-community-client.x86_64 0:5.7.10-1.el7          mysql-community-common.x86_64 0:5.7.10-1.el7
replaced:
 mariadb-libs.x86_64 1:5.5.44-2.el7.centos
complete!
[root@typecodes ~]# clear

最后的截图:

yum安装mysql5.7.10

4 启动数据库:

[root@typecodes ~]# systemctl start mysqld.service

然后使用命令systemctl status mysqld.service查看mysql数据库启动后的服务状态:

systemctl命令查看mysql服务状态

5 获取初始密码

使用yum安装并启动mysql服务后,mysql进程会自动在进程日志中打印root用户的初始密码:

#######从mysql进程日志中获取root用户的初始密码:ra%yk7urcbih
[root@typecodes ~]# grep "password" /var/log/mysqld.log
2016-02-03t10:42:17.272166z 1 [note] a temporary password is generated for root@localhost: ra%yk7urcbih
2016-02-03t10:42:36.776875z 2 [note] access denied for user 'root'@'localhost' (using password: no)
2016-02-03t10:42:52.063138z 3 [note] access denied for user 'root'@'localhost' (using password: no)
2016-02-03t10:42:57.564373z 4 [note] access denied for user 'root'@'localhost' (using password: no)
2016-02-03t10:43:01.477007z 5 [note] access denied for user 'root'@'localhost' (using password: no)
2016-02-03t10:46:03.642008z 6 [note] access denied for user 'root'@'localhost' (using password: no)
2016-02-03t10:46:11.217889z 7 [note] access denied for user 'root'@'localhost' (using password: no)
2016-02-03t10:47:44.755199z 0 [note] shutting down plugin 'validate_password'
2016-02-03t10:47:46.505844z 0 [note] shutting down plugin 'sha256_password'
2016-02-03t10:47:46.505851z 0 [note] shutting down plugin 'mysql_native_password'

6 修改root用户密码

使用小节5中获取的root用户的初始密码,然后进行修改:

set global validate_password_policy =0;//默认是1,即medium,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

set global validate_password_length=4;//指定了密码中数据的长度
alter user root@localhost identified by 'crow';//修改密码

增加远程访问权限

grant all privileges on *.* to 'root'@'%' identified by 'crow' with grant option;
flush privileges;

退出mysql,然后重启服务

systemctl restart mysqld

防火墙打开3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent

重启防火墙

firewall-cmd --reload
[root@typecodes ~]# mysql -uroot -p
enter password:    #######输入默认的root密码后回车
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 2
server version: 5.7.10
copyright (c) 2000, 2015, 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> alter user 'root'@'localhost' identified by 'new password';
query ok, 0 rows affected (0.00 sec)
mysql> exit
bye

7 安装完毕

至此,使用在centos7中使用yum方法安装mysql5.7.10数据库完毕。如下所示,可以使用新的root密码登陆mysql了。

[root@typecodes ~]# mysql -uroot -ppassword
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 3
server version: 5.7.10 mysql community server (gpl)
copyright (c) 2000, 2015, 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> use mysql;
reading table information for completion of table and column names
you can turn off this feature to get a quicker startup with -a
database changed
mysql> show databases;
+--------------------+
| database   |
+--------------------+
| information_schema |
| mysql    |
| performance_schema |
| sys    |
+--------------------+
4 rows in set (0.00 sec)
mysql> clear
mysql> exit
bye
[root@typecodes ~]# clear

附录1:查看mysql数据库的配置信息

mysql的配置文件依然是/etc/my.cnf,其它安装信息可以通过mysql_config命令查看。其中,动态库文件存放在/usr/lib64/mysql目录下。

mysql_config命令查看mysql数据库的安装信息

附录2:对于c/c++等开发者

由于需要用到类似mysql.h等头文件,需要执行下面的命令安装mysql开发版本即可。

[root@typecodes ~]# yum -y install mysql-community-devel

附录3:删除mysql的repository

因为小节3中安装了mysql的yum repository,所以以后每次执行yum操作时,都会去检查更新。如果想要去掉这种自动检查操作的话,可以使用如下命令卸载mysql的repository即可。

[root@typecodes ~]# yum -y remove mysql57-community-release-el7-7.noarch
update 2017.04.10 11:10

使用上面的yum方法也可以安装目前mysql官网上最新的版本mysql5.7.18。只要替换小节2中rmp包的版本即可,后续操作步骤不变。

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

以上所述是小编给大家介绍的centos7.3 安装mysql5.7.18的详细教程,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网