參考了下面兩個連接html
http://www.centoscn.com/mysql/2016/0315/6844.html 連接Amysql
http://www.cnblogs.com/starof/p/4680083.html 連接Bsql
centos7再也不默認安裝mysql,默認安裝的是mariadb,在命令行裏輸入yum install mysql能夠看到提示中顯示要下載mariadb.centos
mariadb的安裝能夠參數連接B中的描述ide
下面是從連接A中獲取的安裝mysql方法.url
在/etc/yum.repos.d目錄中添加一個文件mysql-community.repo,文件內容爲centos7
#Enble to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ enabled=1 gpgcheck=0 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
在命令行中輸入,yum install mysql-community-server,便可以安裝mysql,安裝的是mysql5.6,若是系統中安裝了mariadb,mysql的安裝還會將mariadb刪除.命令行
安裝過程當中還遇到了一個問題server
沒法安裝mysql-InvalidGPGKeyfromfile:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql htm
這裏參考了
http://www.2cto.com/database/201701/586216.html
即將文件/etc/yum.repos.d/mysql-community.repo中的gpgcheck=1改爲gpgcheck=0便可.
這是爲何上面的文件與連接A中的文件內容不一樣的緣由.
啓動mysql
systemctl start mysqld.service
初次安裝mysql是root帳戶是沒有密碼,須要設置一下,
mysql -h localhost -u root -p進入mysql
設置密碼的時候遇到了問題
mysql> set password for ‘root’@‘localhost’ = password('123456'); ERROR 1133 (42000): Can't find any matching row in the user table
解決方法
mysql> grant all on mysql.user to 'root'@'%' identified by 'password'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> update mysql.user set password=password('123456') where user ='root'; Query OK, 5 rows affected (0.00 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)