下载地址
repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/
rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
安装
yum install mysql-community-server -y
启动MYSQL,并加入开机自启
systemctl start mysqld
systemctl status mysqld
systemctl stop mysqld
systemctl enable mysqld
用默认密码进入MYSQL
mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log);
修改密码
set global validate_password_policy = 0;
set password for root@localhost = password('xiaocheng');
远程连接报错
1130 - Host XXX is not allowed to connect to this MySQL server。
解决方案
use mysql;
select host from user where user='root';
方法1
update user set host = '%' where user ='root';
方法2
grant all on *.* to root@'%' identified by 'xiaocheng';
flush privileges;
原因
Host列指定了允许用户登录所使用的IP
user=root Host=192.168.1.1 这里的意思就是说root用户只能通过192.168.1.1的客户端去访问。
user=root Host=localhost 表示只能通过本机客户端去访问。
而%是个通配符,如果Host=192.168.1.%,那么就表示只要是IP地址前缀为“192.168.1.”的客户端都可以连接。如果Host=%,表示所有IP都有连接权限。
注意:在生产环境下不能为了省事将host设置为%,这样做会存在安全问题,具体的设置可以根据生产环境的IP进行设置;