1. 添加MySQL Yum源
MySQL官网>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数据库各个版本信息$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 Serverbaseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/enabled=0 # 禁止gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.7[mysql57-community]name=MySQL 5.7 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/enabled=1 # 安装gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql80-community]name=MySQL 8.0 Community Serverbaseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/enabled=0 # 禁止gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
3. 安装
#执行以下命令安装MySQLyum install mysql-community-server#启动mysql(CentOS7中)systemctl start mysqld.service#低版本的操作系统可用以下指令service mysqld start#查看MySQL状态systemctl status mysqld.service#低版本操作系统可用以下指令service mysqld status
4. 查看并修改密码
$grep "password" /var/log/mysqld.log2019-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端口
授权的方式允许任何主机访问mysql服务器:【一般采用这个即可,限制端口访问交由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遇到的坑总结就是小编为大家收集整理的全部内容了,希望对大家有所帮助。如果您喜欢这篇文章,可以收藏或分享给您的小伙伴们吧!欢迎持续关注我们的后续更新。