##- Centos7安裝mysql5.7社區版mysql
ps:本教程是在必定程度上參考了網絡上的資源結合實際操做總結而成,若有不當指出請大神們批評指正,謝謝!(●'◡'●)sql
###1.從官網下載mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar: http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar數據庫
###2.解壓centos
[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發生了了衝突app
卸載mariadb-libstcp
[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是4060ide
kill -9 4060
再次卸載mariadb-libspost
[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完成!ui
從新安裝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> create 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
###- OK,搞定