參考了下面兩個鏈接
http://www.centoscn.com/mysql/2016/0315/6844.html 鏈接A
http://www.cnblogs.com/starof/p/4680083.html 鏈接B
centos7不再默認安裝mysql,默認安裝的是mariadb,在命令行裏輸入yum install mysql可以看到提示中顯示要下載mariadb.
mariadb的安裝可以參數鏈接B中的描述
下面是從鏈接A中獲取的安裝mysql方法.
在/etc/yum.repos.d目錄中添加一個文件mysql-community.repo,文件內容爲
#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刪除.
安裝過程中還遇到了一個問題
無法安裝mysql-InvalidGPGKeyfromfile:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
這裏參考了
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)