CentOS7安装Redis 安装Mysql5.7

安装Redis

yum install epel-release
yum install redis

yum方式安装的Redis的配置文件位置

vim /etc/redis.conf

设置redis为开机自动启动

chkconfig redis on

常常修改的地方有

1.  修改配置文件,监听所有的IP地址  # bind 127.0.01
2.  配置密码 #requirepass foobared 打开注释,设置密码即可

redis命令操作

启动 service redis restart
停止 service redis stop
重启 service redis restart
查看状态 service redis status

进入本机redis

无密码形式 redis-cli
密码形式 redis-cli -h 127.0.0.1 -p 6379 -a myPassword

为什么选择5.7

因为8.0版本和5.6版本安装和使用太坑了

下载mysql源安装包

# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

安装mysql源

yum localinstall mysql57-community-release-el7-8.noarch.rpm

检查mysql源是否安装成功

# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  74
mysql-tools-community/x86_64      MySQL Tools Community                       74
mysql57-community/x86_64          MySQL 5.7 Community Server                 307

安装时可能会出现类似以下的错误:

Error downloading packages:
mysql-community-client-5.7.27-1.el7.x86_64: [Errno 256] No more mirrors to try.
mysql-community-common-5.7.27-1.el7.x86_64: [Errno 256] No more mirrors to try.

解决方案如下:

1.  清理软件源 yum clean all
2.  建立源数据缓存 yum makecache

安装MySQL

yum install mysql-community-server

安装过程图

静静等待下载和安装即可。若下载速度较慢,如图、则可以ctrl+c强制关掉下载过程,然后重新执行安装命令即可,比较好使。我认为正常速度500-800K

查看安装了哪些包

# rpm -qa | grep mysql
mysql57-community-release-el7-8.noarch
mysql-community-common-5.7.30-1.el7.x86_64
mysql-community-client-5.7.30-1.el7.x86_64
mysql-community-libs-5.7.30-1.el7.x86_64
mysql-community-libs-compat-5.7.30-1.el7.x86_64
mysql-community-server-5.7.30-1.el7.x86_64

启动MySQL服务

service mysqld start
service mysqld status

查看默认随机密码,登录,并且修改

# grep 'temporary password' /var/log/mysqld.log
# mysql -uroot -p
# ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 
# flush privileges;

若通过grep 'temporary password' /var/log/mysqld.log 命令无法输出默认密码则需要
1.删除原来安装过的mysql残留的数据(这一步非常重要,问题就出在这)

rm -rf /var/lib/mysql

2.重启mysqld服务

service mysqld restart

3.再去找临时密码

grep 'temporary password' /var/log/mysqld.log

远程登录

# GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Abcd1234!' WITH GRANT OPTION;
# flush privileges;

默认mysql相关文件地址

配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

修改mysql默认编码为utf8

vim /etc/my.cnf
在[mysqld]下面增加
 character_set_server=utf8
重启MySQL
systemctl restart mysqld
然后进入到mysql查看
show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

卸载mysql

service mysqld stop

rpm -qa | grep -i mysql

mysql-community-server-8.0.13-1.el7.x86_64
mysql-community-libs-8.0.13-1.el7.x86_64
mysql-community-common-8.0.13-1.el7.x86_64
mysql-community-client-8.0.13-1.el7.x86_64

rpm -ev mysql-community-server-8.0.13-1.el7.x86_64  --nodeps
rpm -ev mysql-community-libs-8.0.13-1.el7.x86_64  --nodeps
rpm -ev mysql-community-common-8.0.13-1.el7.x86_64  --nodeps
rpm -ev mysql-community-client-8.0.13-1.el7.x86_64  --nodeps

find / -name mysql

rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /etc/my.cnf

推荐阅读更多精彩内容