阿里雲linux yum源配置
一、備份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
二、下載新的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
三、以後運行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服務。
一、關閉firewall:
service firewalld
stop
systemctl disable firewalld.service
#禁止firewall開機啓動
二、安裝iptables防火牆
yum
install
iptables-services
#安裝
三、編輯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 root@localhost=password('youpassword');
set password for root@127.0.0.1=password('youpassword');
3.exit退出mysql
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 yourusername@localhost identified by 'yourpassword';
11.給帳號開通外網全部權限
grant all privileges on mmall.* to 'yourusername'@'%'identified by 'yourpassword';
ps:根據實際修改權限
列:
grant select,insert,update on mmall.* to yourusername@'192.11.11.11'identified by 'yourpassword';
表明只開通增改查給指定帳號,並指定ip地址
12使操做生效flush privileges;
MySQL驗證
1.Linux:執行ifconfig查看運行mysql服務器的ip地址
2.windows:執行ipconfig
3.使用navicat鏈接數據庫:
建立數據庫
1. create database `mmall` default character set utf8 COLLATE utf8_general_ci;
2.show datebases;
3.grant all privileges on mmall.* to yourusername@localhost 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;