MySQL部署-CentOS7.X
一、下载和安装MySQL
ps:必须处在 /root 目录中操作
下载:wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
安装repo:yum -y install mysql57-community-release-el7-10.noarch.rpm
安装服务器:yum -y install mysql-community-server
二、MySQL配置
-
启动MySQL
systemctl start mysqld.service
-
查看MySQL启动状态,显示active表明服务已启动
systemctl status mysqld.service
-
登入MySQL
查看初始密码:mysql> grep "password" /var/log/mysqld.log 进入数据库: mysql> mysql -uroot -p 修改初始密码:mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password'; // 新密码默认要大于等于8位,而且不能太简单,至于如何修改密码策略,问题及处理那边会说明
-
启动远程访问(ip 为MySQL的 ip,如要开启所有的,用%代替ip )
mysql> grant all privileges on *.* to 'root'@'ip' identified by 'new password' with grant option;
-
刷新MySQL
mysql> flush privileges;
-
退出MySQL
mysql> exit;
三、关闭防火墙
虽然可以开放端口,可是对于本地虚拟机用于开发学习的,不想每次安装一些应用就要开放特定端口这么麻烦,直接关闭一劳永逸
关闭防火墙,不过开机启动:systemctl stop firewalld.service
永久关闭:systemctl disable firewalld.service
查看防火墙状态:firewall-cmd --state
问题及处理
-
密码设置简单问题
问题:mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 解决: 1、首先必须先设置新的密码 2、输入:mysql> SHOW VARIABLES LIKE 'validate_password%'; 3、设置密码策略为最低:mysql> set global validate_password_policy=0; 4、设置密码最少长度大于等于4:mysql> set global validate_password_length=4; 5、就可以设置简单的密码: mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123'; Query OK, 0 rows affected (0.00 sec)
-
出现:-bash: XXX: command not found 问题时,要下载对应的应用
问题:-bash: wget: command not found 解决:yum -y install wget