1 安装yum源
yum localinstall http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
2 参看源
vi /etc/yum.repos.d/mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
3 刷新源
yum repolist enabled | grep mysql
4 安装Mysql
yum install mysql-community-server
5 启动管理
systemctl start mysqld #启动MySQLDB
systemctl stop mysqld #停止MySQLDB
systemctl restart mysqld #重启MySQLDB
systemctl enable mysqld #设置开机启动
6 查看默认密码
sudo grep 'temporary password' /var/log/mysqld.log
7 登录,使用默认密码
mysql -uroot -p
8 修改默认密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
9 外部可以访问设置
grant ALL PRIVILEGES ON *.* to 'root'@'%' identified by 'MyNewPass4' WITH GRANT OPTION;
注意 root 为登录名 % 为任意IP 指定IP 如下
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’192.168.1.3′ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;