mysql5.7安装
1:安装
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum -y install mysql-server
systemctl start mysqld
2:找初始密码:
# grep "temporary password" /var/log/mysqld.log
2020-07-01T01:37:50.408894Z 1 [Note] A temporary password is generated for root@localhost: (<Cxcy</i3Wa
3:更改密码:
[root@dev-base1 /root]
# mysql -u root -p
Server version: 5.7.30
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '3333333333';
Query OK, 0 rows affected (0.01 sec)
4:开启远程连接:
show databases;
use mysql;
show tables;
update user set Host='%' where User='root';
grant all privileges on *.* to root@"192.168.%" identified by "3333333333";
flush privileges;
5:配置默认编码为utf8,忽略大小写
vi /etc/my.cnf
# 添加 [mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
lower_case_table_names=1
6:更改mysql安装目录:
先创建目录
[root@dev-base1 /data]
# cd /data
# mkdir MySQLData
# chmod 777 /data/MySQLData
停止数据库
# systemctl stop mysqld
复制数据目录 & 备份原有数据目录
# cp -R /var/lib/mysql /data/MySQLData
# mv /var/lib/mysql /var/lib/mysql_bak
# chown -R mysql:mysql /data/MySQLData
修改配置文件:
# vim /etc/my.cnf
添加配置:
datadir=/data/MySQLData/mysql
socket=/data/MySQLData/mysql.sock
log-error=/data/MySQLData/mysql/mysqld.log
启动数据库&设置开机自启
# systemctl restart mysqld
# systemctl enable mysqld
7:查看启动进程:
[root@dev-base1 /data/MySQLData]
# ps -ef |grep mysql
mysql 1183 1 1 10:06 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 1213 62664 0 10:07 pts/0 00:00:00 grep --color=auto mysql
8:登录测试:
[root@dev-base1 /data/MySQLData]
# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决mysql.sock问题:
[root@dev-base1 /data/MySQLData]
# mkdir -p /var/lib/mysql
[root@dev-base1 /data/MySQLData]
# ln -s /data/MySQLData/mysql.sock /var/lib/mysql/mysql.sock
[root@dev-base1 /data/MySQLData]
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
redis4.0安装
1:安装
[root@dev-base1 /root]
# wget http://download.redis.io/releases/redis-4.0.6.tar.gz
# tar xzf redis-4.0.6.tar.gz -C /usr/local/
# cd /usr/local
# mv redis-4.0.6 redis
2:编译
# cd redis && make
3:软连接执行命令
[root@dev-base1 /usr/local/redis/src]
# ln -s /usr/local/redis/src/redis-server /usr/local/bin/redis-server
[root@dev-base1 /usr/local/redis/src]
# ln -s /usr/local/redis/src/redis-cli /usr/local/bin/redis-cli
4:配置数据和日志目录:
# mkdir -p /data/redis/{data,logs}
5:拷贝配置文件模板
[root@dev-base1 /usr/local/redis]
# cp redis.conf /data/redis/
6:更改配置文件:
修改绑定地址和日志目录,数据目录
[root@dev-base1 /data/redis]
# vim redis.conf
bind 192.168.15.253
logfile "/data/redis/logs/redos.log"
dir /data/redis/data
daemonize yes
requirepass 3333333333
7:启动redis
[root@dev-base1 /data/redis]
# redis-server redis.conf
8:加入开机自启动
[root@dev-base1 /data/redis] vim /lib/systemd/system/redis.service
=========================
# 内容
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/bin/redis-server /data/redis/redis.conf --supervised systemd
ExecStop=/usr/libexec/redis-shutdown
Type=notify
User=root
Group=root
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
==========================
[root@dev-base1 /data/redis] systemctl daemon-reload
[root@dev-base1 /data/redis] systemctl start redis
[root@dev-base1 /data/redis] systemctl enable redis