1.下載mysql的repo源mysql
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpmsql
2.安裝mysql-community-release-el7-5.noarch.rpm包bash
$ 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。ide
3.安裝mysqlrest
$ sudo yum install mysql-servercode
根據提示安裝就能夠了,不過安裝完成後沒有密碼,須要重置密碼server
4.重置mysql密碼blog
$ mysql -u rootip
登陸時有可能報這樣的錯: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 > FLUSH PRIVILEGES;
若是mysql -u root遇到/var/lib/mysql/mysql.sock錯誤的時候
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
遠程使用workbench登陸MySQL
mysql -u root -p #登陸MySQL use mysql; #庫 select host,user,password from user; #表中存放的是有訪問權限的用戶和ip grant all privileges on *.* to 'root'@'你的IP' identified by 'root' with grant option; # 添加用戶 flush privileges; set password for 'root'@'你的IP'=password('你的密碼'); # 更改密碼