- Centos7安装mysql5.7社区版
ps:本教程是在一定程度上参考了网络上的资源结合实际操作总结而成
1.从官网下载:
mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
2.解压
[root@localhost ~]# 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
2.安装:
[root@localhost ~]# rpm -i mysql-community-common-5.7.16-1.el7.x86_64.rpm warning: mysql-community-common-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.16-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.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/dutch/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/english/errmsg.sys from install of mysql-community-common-5.7.16-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.16-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.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/german/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/greek/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/italian/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/japanese/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/korean/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/polish/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/romanian/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/russian/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/serbian/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/slovak/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/spanish/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/swedish/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64 file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.16-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64
说明安装过程中与mariadb-libs发生了了冲突
卸载mariadb-libs
[root@localhost ~]# yum -y remove mariadb-libs.x86_64 Existing lock /var/run/yum.pid: another copy is running as pid 4060. Another app is currently holding the yum lock; waiting for it to exit... The other application is: PackageKit Memory : 118 M RSS (1.4 GB VSZ) Started: Sun Nov 20 09:57:20 2016 - 04:54 ago State : Sleeping, pid: 4060
提示yum被锁住了pid是4060
kill -9 4060
再次卸载mariadb-libs
[root@localhost ~]# yum -y remove mariadb-libs.x86_64 BDB2053 Freeing read locks for locker 0x3da: 4060/140620739848000 BDB2053 Freeing read locks for locker 0x3dc: 4060/140620739848000 Loaded plugins: fastestmirror, langpacks Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be erased --> 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 --> Running transaction check ---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved =============================================================================================================================================================================================================== Package Arch Version Repository Size =============================================================================================================================================================================================================== Removing: mariadb-libs x86_64 1:5.5.44-2.el7.centos @anaconda 4.4 M Removing for dependencies: postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M Transaction Summary =============================================================================================================================================================================================================== Remove 1 Package (+1 Dependent package) Installed size: 17 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2 Erasing : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 2/2 Verifying : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 1/2 Verifying : 2:postfix-2.10.1-6.el7.x86_64 2/2 Removed: mariadb-libs.x86_64 1:5.5.44-2.el7.centos Dependency Removed: postfix.x86_64 2:2.10.1-6.el7 Complete!
卸载mariadb-libs完成!
重新安装mysql-community-common-5.7.16-1.el7.x86_64.rpm
[root@localhost ~]# rpm -i mysql-community-common-5.7.16-1.el7.x86_64.rpm warning: mysql-community-common-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
搞定!
接下来依次安装:
[root@localhost ~]# rpm -i mysql-community-libs-5.7.16-1.el7.x86_64.rpm warning: mysql-community-libs-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY [root@localhost ~]# rpm -i mysql-community-client-5.7.16-1.el7.x86_64.rpm warning: mysql-community-client-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY [root@localhost ~]# rpm -i mysql-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/SHA1 Signature, key ID 5072e1f5: NOKEY
3.启动mysql:
[root@localhost ~]# service mysqld start Redirecting to /bin/systemctl start mysqld.service
4.查看密码:
由于该版本安装后,mysql会自动生成一个随机密码在/var/log/mysqld.log中
查看密码
[root@localhost ~]# cat /var/log/mysqld.log|grep -n password
会看到其中有一行类似下面:
6:2016-11-20T15:12:19.209149Z 1 [Note] A temporary password is generated for root@localhost: Jj!LR+pj>2ad
其中Jj!LR+pj>2ad就是密码了。
5.登陆:
[root@localhost ~]# mysql -u root -p Enter password:
6.登陆成功后用命令修改密码
mysql> alter user 'root'@'localhost' identified by '123456'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements //密码强度不够校验没通过
7.降低密码强度(可选)
mysql> set global validate_password_policy =0; //默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。 mysql> set global validate_password_length=4; //指定了密码中数据的长度
8.修改密码
mysql> alter user root@localhost identified by '123456'; Query OK, 0 rows affected (0.00 sec)
成功
9.创建数据库
mysql> crate database rise;
rise是数据库名
10.创建用户远程并赋予远程连接的权限
mysql> grant all privileges on rise.* to val@'%' identified by '123456'; mysql> flush privileges;
%表示任意IP(可以指定IP)、val是用户名、123456是密码
11.使用nativecat远程连接数据
提示:2003 -Can't connect to MySQL server on '10.0.0.18'(10038)
说明端口不通
12.开通3306端口
Centos升级到7之后,发现无法使用iptables控制Linuxs的端口,google之后发现Centos 7使用firewalld代替了原来的iptables。
下面记录如何使用firewalld开放Linux端口:
开启端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
命令含义:
–zone #作用域
–add-port=3306/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
[root@localhost ~]# firewall-cmd --reload