Centos7下mysql5.7社区版安装步骤

mysql安装步骤

1.检查mysql是否安装语法:

[root@localhost mysql]# rpm -qa|grep mysql
依赖包
mysql-community-libs-5.7.16-1.el7.x86_64
mysql-community-client-5.7.16-1.el7.x86_64
mysql-community-server-5.7.16-1.el7.x86_64
mysql-community-common-5.7.16-1.el7.x86_64


2.删除依赖包
[root@localhost mysql]# rpm -e mysql-community-libs-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-client-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-server-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-common-5.7.16-1.el7.x86_64 --nodeps


3.解压命令:
tar -xvf  mysql包名
[root@localhost mysql]# tar -xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm 
mysql-community-libs-5.7.16-1.el7.x86_64.rpm 
mysql-community-common-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-test-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-5.7.16-1.el7.x86_64.rpm 
mysql-community-client-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-5.7.16-1.el7.x86_64.rpm

4.安装
依次执行(几个包有依赖关系,所以执行有先后)下面命令安装 
[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm 
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm 
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm 
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm 


在安装rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm的时候报错如下: 
[root@linux_node_1 src]# rpm -ivhmysql-community-server-5.7.16-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1Signature, key ID 5072e1f5: NOKEY 
error: Failed dependencies: 
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64 
libaio.so.1(LIBAIO_0.1)(64bit) is needed bymysql-community-server-5.7.16-1.el7.x86_64 
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
net-tools is needed by mysql-community-server-5.7.16-1.el7.x86_64


这个报错的意思是需要安装libaio包和net-tools包:
yum install libaio 
yum install net-tools 


完成之后就可以顺利安装 
5.为了保证数据库目录与文件的所有者为 mysql 登陆用户,如果你是以 root 身份运行 mysql 服务,需要执行下面的命令初始化 
mysqld –initialize –user=mysql 

[root@localhost mysql]#cat /var/log/mysqld.log |grep password(此处建议手敲,复制粘贴有小问题)
2017-11-08T14:18:26.633043Z 1 [Note] A temporary password is generated for root@localhost: -aMOucQV+0_T (mysql登陆密码)
2017-11-08T14:19:11.954265Z 2 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-11-08T14:19:43.764174Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-11-08T14:20:50.055048Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-11-08T14:21:08.226061Z 5 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-11-08T14:21:23.363104Z 6 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-11-08T14:24:04.230363Z 0 [Note] Shutting down plugin 'validate_password'
2017-11-08T14:24:05.280400Z 0 [Note] Shutting down plugin 'sha256_password'
2017-11-08T14:24:05.280402Z 0 [Note] Shutting down plugin 'mysql_native_passwor'
2017-11-08T14:49:05.317902Z 0 [Note] Shutting down plugin 'validate_password'
2017-11-08T14:49:07.294277Z 0 [Note] Shutting down plugin 'sha256_password'
2017-11-08T14:49:07.294279Z 0 [Note] Shutting down plugin 'mysql_native_passwor'
2017-11-08T14:51:53.324364Z 0 [Note] Shutting down plugin 'validate_password'
2017-11-08T14:51:55.061297Z 0 [Note] Shutting down plugin 'sha256_password'
2017-11-08T14:51:55.061299Z 0 [Note] Shutting down plugin 'mysql_native_passwor'
2017-11-08T15:05:33.092434Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2017-11-08T15:13:51.780264Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2017-11-08T15:24:24.791509Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO)


6.登陆

[root@localhost mysql]# mysql -uroot -p
Enter password:  
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.16


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

7.修改密码

mysql>  set password=password('新密码');
Query OK, 0 rows affected, 1 warning (0.06 sec)
mysql> 


注意:新密码要有特殊符号'$'等 首字母大写 密码8位数;


9.然后测试密码是否修改成功!
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.16 MySQL Community Server (GPL)


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


10.测试成功后,可以开启3306端口

1、检测并打开firewall
systemctl status firewalld.service #检测是否开启了firewall
systemctl stop firewalld.service #关闭firewall
systemctl startfirewalld.service #开启firewall
sytsemctl disable firewalld.service #禁止firewall开机自启
2.CentOS 7 采用了 firewalld防火墙
如要查询是否开启3306
firewall-cmd --query-port=3306/tcp 
如果打印no,显示3306端口未开启
下面我们开启3306端口:
firewall-cmd--add-port=3306/tcp --permanent(永久开启端口)


设置MySQL服务开机自启动。
# chkconfig mysql on

重启msql服务
systemctl restart mysqld.service




[root@localhost mysql]# rpm -qa|grep mysql
依赖包
mysql-community-libs-5.7.16-1.el7.x86_64
mysql-community-client-5.7.16-1.el7.x86_64
mysql-community-server-5.7.16-1.el7.x86_64
mysql-community-common-5.7.16-1.el7.x86_64


删除依赖包
[root@localhost mysql]# rpm -e mysql-community-libs-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-client-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-server-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-common-5.7.16-1.el7.x86_64 --nodeps


解压命令:
tar -xvf mysql包名
[root@localhost mysql]# tar -xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm 
mysql-community-libs-5.7.16-1.el7.x86_64.rpm 
mysql-community-common-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-test-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-5.7.16-1.el7.x86_64.rpm 
mysql-community-client-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-5.7.16-1.el7.x86_64.rpm

[root@localhost mysql]# rpm -qa|grep mysql
依赖包[root@localhost mysql]# rpm -qa|grep mysql
依赖包
mysql-community-libs-5.7.16-1.el7.x86_64
mysql-community-client-5.7.16-1.el7.x86_64
mysql-community-server-5.7.16-1.el7.x86_64
mysql-community-common-5.7.16-1.el7.x86_64


删除依赖包
[root@localhost mysql]# rpm -e mysql-community-libs-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-client-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-server-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-common-5.7.16-1.el7.x86_64 --nodeps


解压命令:
tar -xvf mysql包名
[root@localhost mysql]# tar -xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm 
mysql-community-libs-5.7.16-1.el7.x86_64.rpm 
mysql-community-common-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-test-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-5.7.16-1.el7.x86_64.rpm 
mysql-community-client-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-5.7.16-1.el7.x86_64.rpm
mysql-community-libs-5.7.16-1.el7.x86_64
mysql-community-client-5.7.16-1.el7.x86_64
mysql-community-server-5.7.16-1.el7.x86_64
mysql-community-common-5.7.16-1.el7.x86_64


删除依赖包
[root@localhost mysql]# rpm -e mysql-community-libs-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-client-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-server-5.7.16-1.el7.x86_64 --nodeps
[root@localhost mysql]# rpm -e mysql-community-common-5.7.16-1.el7.x86_64 --nodeps


解压命令:
tar -xvf mysql包名
[root@localhost mysql]# tar -xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm 
mysql-community-libs-5.7.16-1.el7.x86_64.rpm 
mysql-community-common-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm 
mysql-community-test-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm 
mysql-community-server-5.7.16-1.el7.x86_64.rpm 
mysql-community-client-5.7.16-1.el7.x86_64.rpm 
mysql-community-embedded-5.7.16-1.el7.x86_64.rpm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值