1.下載mysql的repo源mysql
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpmsql
2.安裝mysql-community-release-el7-5.noarch.rpm包socket
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpmrest
安裝這個包後,會得到兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。server
3.安裝mysqlget
$ sudo yum install mysql-serverit
根據提示安裝就能夠了,不過安裝完成後沒有密碼,須要重置密碼登錄
4.重置mysql密碼date
$ mysql -u rootservice
登陸時有可能報這樣的錯:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),緣由是/var/lib/mysql的訪問權限問題。下面的命令把/var/lib/mysql的擁有者改成當前用戶:
$ sudo chown -R root:root /var/lib/mysql
重啓mysql服務
$ service mysqld restart
接下來登陸重置密碼:
$ mysql -u root //直接回車進入mysql控制檯mysql > use mysql;mysql > update user set password=password('123456') where user='root';mysql > exit;