centos之yum方式安装mysql
Centos-7修改yum源为国内的yum源
国外地址yum源下载慢,下到一半就断了,就这个原因就修改它为国内yum源地址
国内也就是ali 与 网易
以centos7为例 ,以 修改为阿里的yum源
-
备份本地yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
-
获取阿里yum源配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
-
更新cache
yum makecache
-
查看
yum -y update
下载并安装MySQL官方的 Yum Repository
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
使用上面的命令就直接下载了安装用的Yum Repository,然后就可以直接yum安装了。
[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
安装MySQL服务器
[root@localhost ~]# yum -y install mysql-community-server
MySQL数据库设置
启动MySQL
[root@localhost ~]# systemctl start mysqld.service
查看MySQL运行状态,运行状态如图
[root@localhost ~]# systemctl status mysqld.service
MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码
[root@localhost ~]# grep "password" /var/log/mysqld.log
输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
这里有个问题,新密码设置的时候如果设置的过于简单会报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
原因是因为MySQL有密码设置的规范,具体是与validate_password_policy的值有关:
Policy | Tests Performed |
---|---|
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
ERROR:1819问题解决(mysql密码复杂度解决)
登录mysql
修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_mixed_case_count=2;
Query OK, 0 rows affected (0.00 sec)
修改结果(正确配置)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_dictionary_file | |
| validate_password_length | 6 |
| validate_password_mixed_case_count | 2 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
6 rows in set (0.00 sec)
修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
到这里安装成功
设置mysql远程访问
mysql设置远程访问详细参考该博客
https://www.cnblogs.com/goxcheer/p/9420460.html