安裝mysql有兩種:php
1-能夠使用yum安裝,html
2-能夠本身下載安裝包安裝mysql,mysql
騰訊雲的centos系統自帶了yum,因此用yum安裝方便點sql
安裝步驟centos
1-查看yum源中是否有mysqlsocket
yum list | grep mysql
2-發現沒有想要的mysql-server服務,只有php和其餘的mysql安裝包rest
3-下載mysql的repo源server
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
4-安裝mysql-community-release-el7-5.noarch.rpm包htm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
5-安裝mysql服務blog
sudo yum install mysql-server
6-登陸mysql並修改mysql的密碼
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 mysql:mysql /var/lib/mysql #這裏的mysql是用戶名(須要設置用戶組合用戶)
7-重啓mysql
service mysqld restart
8-重置密碼
$ mysql -u root mysql > use mysql; mysql > update user set password=password('tiger') where user='root'; mysql > exit;