在阿里云centos7.3上创建用户以及配置Mysql

                                                                   阿里云linux yum源配置
1、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3、之后运行yum makecache生成缓存

                                                             服务器上新建用户
useradd -d /usr/whohim -m whohim
cd /usr/whohim/
passwd whohim
sudo vim /etc/sudoers
在搜索root 在下面写用户的权限跟root管理员一样
exit
登录whohim账号
                                                                       安装MySQL

yum -y install mysql-server
rpm -qa|grep mysql-server #检查是否安装mysql-server
字符集配置:
vim /etc/my.cnf
在mysqld节点下添加
character-set-server=utf8
default-character-set=utf8
保存退出
配置mysql的自启动:
systemctl enable mysqld
systemctl list-unit-files --type=service
systemctl restart mysqld

CentOS切换为iptables防火墙

切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。
1、关闭firewall:
service firewalld stop
systemctl disable firewalld.service #禁止firewall开机启动

2、安装iptables防火墙
yum install iptables-services #安装

3、编辑iptables防火墙配置
vi /etc/sysconfig/iptables #编辑防火墙配置文件

下边是一个完整的配置文件:
Firewall configuration written by system-config-firewall

Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT
:wq! #保存退出
service iptables start #开启
systemctl enable iptables.service #设置防火墙开机启动
配置防火墙
sudo vim /etc/sysconfig/iptables
添加
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
重启防火墙
systemctl  restart iptables
此时报错,遂我放弃使用iptables改用centos7.3自带的firewall,反正旧的不去新的不来,总要拥抱新技术的。

卸载iptable,停止服务
yum安装firewalld
sudo yum -y install firewalld

 sudo systemctl start firewalld
 sudo systemctl enable firewalld
 sudo systemctl status firewalld

sudo firewall-cmd --zone=public --add-port=5000/tcp --permanent

直接设置端口会报这个错:firewall-cmd: command not found,要先做上两步

随便设置80端口和3306端口
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
最后重载:
sudo firewall-cmd --reload

                                                                     MySQL服务启动
1.启动MySQL服务
systemctl restart mysql
卡主没反应
然后 mysql -u root进入数据库又报 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
看不出问题,查看mysql的日志终于找到问题vim /var/log/mysqld.log
搜索 Plugin 'FEDERATED' is disabled. /usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
原因: 
table ‘mysql.host’不存在的原因是因为新安装的mysql服务后,一般需要执行数据库初始化操作 ,从而生成与权限相关的表,执行命令如下:
/usr/bin/mysql_install_db --user=mysql
再执行systemctl restart mysql成功。
mysql -u root进入数据库
                                                                      MySQL配置
1.查看当前用户
select user,host,password from mysql.user;
2.修改root密码:
set password for [email protected]=password('youpassword');
set password for [email protected]=password('youpassword');
3.exit退出mysql
4.重新登录mysql输入mysql -u root -p     -p, --password[=name] //输入密码  参考:(http://www.cnblogs.com/iloveyoucc/archive/2012/03/09/2388130.html

5.输入密码登录成功
6.删除匿名用户,执行以下sql
查看是否有匿名用户select user,host from mysql.user;
删除匿名用户delete from mysql.user where user='';
再次查看select user,host from mysql.user;
刷新,使以上操作生效flush privileges;
7.插入mysql新用户
GRANT USAGE ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
8.使操作生效flush privileges;
9.创建新的database
CREATE DATABASE `mmall`
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
10.本地用户赋予所有权限
grant all privileges on mmall.* to [email protected] identified by 'yourpassword';
11.给账号开通外网所有权限
grant all privileges on mmall.* to 'yourusername'@'%'identified by 'yourpassword';
ps:根据实际修改权限
列:grant select,insert,update on mmall.* to [email protected]'192.11.11.11'identified by 'yourpassword';
代表只开通增改查给指定账号,并指定ip地址
12使操作生效flush privileges;
                                                                
                                                               MySQL验证
1.Linux:执行ifconfig查看运行mysql服务器的ip地址
2.windows:执行ipconfig
3.使用navicat连接数据库:     
  在阿里云centos7.3上创建用户以及配置Mysql在阿里云centos7.3上创建用户以及配置Mysql

                                                         创建数据库
 1. create database `mmall` default character set utf8 COLLATE utf8_general_ci;    
 2.show datebases;    
 3.grant all privileges on mmall.* to [email protected] identified by 'yourpassword';     
 4.flush privileges; 
 5.将数据表移动到云上去:
   exit
   cd/product/developer/
   输入密码; 
   pwd,复制路径,进入数据库
  user mmall;
  show tables;
  source  /usr/whohim/product/developer/mmall.sql
  show tables;
  查看一下表有没有数据select * from mmall_user\G;