1. 添加MySQL Yum源
MySQL官網(wǎng)>DOWNLOADS>MySQL Yum Repository找到合適版本的yum源
$wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
$sudo rpm -Uvh mysql80-community-release-el7-2.noarch.rpm
#查看MySQL數(shù)據(jù)庫各個版本信息
$yum repolist all | grep mysql
2. 選擇安裝版本
修改/etc/yum.repos.d/mysql-community.repo 文件,選擇MySQL5.7版本
# 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
# Enable to use MySQL 5.7
[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
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0 # 禁止
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
3. 安裝
#執(zhí)行以下命令安裝MySQL
yum install mysql-community-server
#啟動mysql(CentOS7中)
systemctl start mysqld.service
#低版本的操作系統(tǒng)可用以下指令
service mysqld start
#查看MySQL狀態(tài)
systemctl status mysqld.service
#低版本操作系統(tǒng)可用以下指令
service mysqld status
4. 查看并修改密碼
$grep "password" /var/log/mysqld.log
2019-04-11T08:17:16.706096Z 1 [Note] A temporary password is generated for root@localhost: ux#bkaM(k1q-
$mysql -u root -p
>ux#bkaM(k1q-
# 修改密碼
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'complex password';
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=1;
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'simple password';
5. 配置開放3306端口
授權(quán)的方式允許任何主機訪問mysql服務(wù)器:【一般采用這個即可,限制端口訪問交由firewalld來做】
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
限定ip訪問:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@'10.10.50.127' IDENTIFIED BY 'password' WITH GRANT OPTION;
以上就是centos7 安裝mysql和mysqlclient遇到的一些坑和需要注意的知識點總結(jié),感謝大家的閱讀和對腳本之家的支持。