1疚脐、下載并安裝
#下載mysql rpm包
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
#安裝mysql rpm包
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
#安裝mysql
yum install mysql-community-server
2津函、啟動(dòng)服務(wù)并更新密碼
#重啟mysql服務(wù)
service mysqld restart
#新安裝mysql5.7會(huì)隨機(jī)生成一個(gè)密碼等龙,查看密碼
grep "password" /var/log/mysqld.log
#使用隨機(jī)密碼登陸到mysql(隨機(jī)密碼有特殊字符黄娘,請(qǐng)用單引號(hào)引起來)
mysql -uroot -p['隨機(jī)密碼']
#mysql5.7中有簡(jiǎn)易密碼驗(yàn)證账嚎,若要去掉驗(yàn)證
set global validate_password_policy=0;
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=3;
set global validate_password_special_char_count=0;
set global validate_password_length=3;
#更新mysql密碼
set password = password('NewPassword');
#關(guān)閉防火墻
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機(jī)啟動(dòng)
firewall-cmd --state #查看默認(rèn)防火墻狀態(tài)(關(guān)閉后顯示notrunning,開啟后顯示running)
3雄卷、root密碼忘記
#在my.cnf配置文件中加入以下語句搓蚪,在[mysqld]中添加
skip-grant-tables
#重啟mysql
service mysqld restart
#使用無密碼登錄
mysql
#選擇數(shù)據(jù)庫并修改密碼并刷新權(quán)限
use mysql;
update user set authentication_string=password('123456') where user='root';
flush privileges;
exit;
#刪除之前新增的配置信息
skip-grant-tables
#重啟mysql
service mysqld restart