下載mysql
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm 解壓
yum install mysql-community-server 安裝服務(wù)
systemctl start mysqld.service 啟動(dòng)服務(wù)
grep 'temporary password' /var/log/mysqld.log 查看臨時(shí)密碼
mysql -uroot -p
mysql5.7默認(rèn)安裝了密碼安全檢查插件(validate_password),默認(rèn)密碼檢查策略要求密碼必須包含:大小寫字母、數(shù)字和特殊符號(hào)吉嫩,并且長(zhǎng)度不能少于8位。否則會(huì)提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯(cuò)誤油挥,如下圖所示
set global validate_password_policy=0; 修改密碼安全等級(jí)
set global validate_password_length=6; 修改密碼長(zhǎng)度
允許遠(yuǎn)程連接
mysql>use mysql;
mysql>update user set host = '%' where user= 'root';
mysql> grant all privileges on . to 'root'@'%' with grant option;
mysql>flush privileges;
本地連接出現(xiàn)2003錯(cuò)誤
解決辦法關(guān)閉防火墻
systemctl stop firewalld.service
systemctl disable firewalld.service #禁止firewall開機(jī)啟動(dòng)
再次本地連接
如果你centos版本低可以安裝低版本mysql
yum install -y mysql-server mysql mysql-devel
service mysqld start
最后設(shè)置root賬號(hào)密碼為root:mysqladmin -u root password 'root'
進(jìn)入mysql
允許遠(yuǎn)程連接
mysql> GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY "root";
mysql> flush privileges;