MySQL安装步骤(centos)
1,直接使用yum快速搭建
使用一下命令
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
完成以后启动mysql服务
启动
systemctl start mysqld.service
停止
systemctl stop mysqld.service
2,登录mysql 创建用户,允许远程登录
我使用上面说的密码还不能登录,只有先设置免密登录设置账户了😓
命令:
[root@iZm5ec741lskog8pdkr3omZ ~]# vim /etc/my.cnf
在mysqld下面添加
skip-grant-tables
设置重设root密码,设置远程登录权限
先刷新
flush privileges;
创建用户
mysql>create user 'test'@'localhost' identified by 'qwerty';或
mysql> grant all privileges on *.* to 'test1'@'%' identified by 'qwerty';
最后保存
mysql>flush privileges;
在设置my.cnf里去掉免密码的设置,使用密码登录
mysql -u root -p
3 阿里云服务器开启远程端口
这个时候远程登录还是不行的,因为阿里云的安全策略只开放一些端口,mysql的3306禁止远程访问的
配置一下端口就可以了,
配置apache服务器
yum install httpd
systemctl start httpd.service
远程登录不了的解决办法。
原因:默认情况下mysql为安全起见,不支持远程登录mysql,所以需要设置开启 远程登录mysql的权限
登录mysql后输入如下命令:
grant all privileges on *.* to 'root' @'%' identified by 'root';
flush privileges;
原因:端口3306没有对外开放
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save ---将修改永久保存到防火墙中
之前在CentOS安装完MySQL修改默认密码时出现了如下错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
如果想要查看MySQL完整的初始密码规则,登陆后执行以下命令
SHOW VARIABLES LIKE 'validate_password%';
密码的长度是由validate_password_length决定的,但是可以通过以下命令修改
set global validate_password_length=4;
validate_password_policy决定密码的验证策略,默认等级为MEDIUM(中等),可通过以下命令修改为LOW(低)
set global validate_password_policy=0;
新建用户授权
//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录。
@>mysql -u root -p
@>密码
//首先为用户创建一个数据库(fe)
mysql>
create
database
fe;
//授权fe_group用户拥有fe数据库的所有权限
@>
grant
all
privileges
on
fe.*
to
fe_group@localhost identified
by
'123456'
;
//localhost是本地访问,其他地址访问不了,%是所有
@>
grant
all
privileges
on
fe.*
to
fe_group@
'%'
identified
by
'123456'
;
//刷新系统权限表
mysql>flush
privileges;
(原文:
https://www.cnblogs.com/yangwenzhi/p/9186913.html)
查看mysql所有用户
使用shell命令MySQL -uroot -p
输入密码后再select user,host from mysql.user;
创建普通用户及密码
create user **** identified by '*****';
给予用户数据库的所有权限
grant all on shanghui.* to 'shanghui'@'%';
刷新数据库
flush privileges;