CentOS7默認數據庫是mariadb,配置等用着不習慣,所以決定改爲mysql,可是CentOS7的yum源中默認好像是沒有mysql的。爲了解決這個問題,咱們要先下載mysql的repo源。mysql
1.下載mysql的repo源linux
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpmsql
2.安裝mysql-community-release-el7-5.noarch.rpm包數據庫
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpmsocket
安裝這個包後,會得到兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。spa
3.安裝mysqlrest
$ sudo yum install mysql-serverserver
根據提示安裝就能夠了,不過安裝完成後沒有密碼,須要重置密碼get
4.重置mysql密碼it
$ mysql -u root
登陸時有可能報這樣的錯: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:
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;
處理完後,記得重啓mysql服務:
$ systemctl restart mysql