软件:

        VM虚拟机

        CentOS7

        Mysql5.7

安装:

        更换yum源

        1、更换国内yum源 阿里或者网易(先安装wget)        

yum install wget -y

        2、备份旧yum源文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

        3、更换为阿里yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

        4、更新本地缓存

yum clean all

yum makecache

        mysql安装

         1、获取官网5.7rpm包

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

        2、使用rpm安装

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

        3、安装mysql服务

yum -y install mysql-server

        4、修改Mysql配置文件

vi /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# 设置3306端口
port = 3306

# 允许最大连接数
max_connections=1000

# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8

# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

# sqlmodel设置
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8

        5、mysql启动

systemctl start mysqld//启动命令

systemctl stop mysqld//关闭服务

systemctl restart mysqld//重启服务

systemctl enable mysqld//设置开机自启动

        6 、在日志文件中获取安装时生成的默认密码

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

        7、登录mysql(输入上一步获取的密码)

mysql -uroot -p默认密码

        8、修改密码为“123456”

alter user 'root'@'localhost' identified by '123456';

        

        远程访问设置       

        

        1、修改远程访问权限

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

        2、刷新权限

flush privileges;

       3、防火墙设置

systemctl status firewalld//查看防火墙状态

//active状态下需要开启3306端口的访问

firewall-cmd --zone=public --add-port=3306/tcp --permanent//开启3306端口

firewall-cmd --reload//重启防火墙

//关闭防火墙
systemctl stop firewalld.service

        完成安装配置可远程连接使用。

完全卸载

        1、查看mysql安装情况

rpm -qa | grep -i mysql
[root@node04 ~]# rpm -qa | grep -i mysql
mysql-community-server-5.7.36-1.el7.x86_64
mysql-community-common-5.7.36-1.el7.x86_64
mysql-community-libs-compat-5.7.36-1.el7.x86_64
mysql-community-libs-5.7.36-1.el7.x86_64
mysql57-community-release-el7-11.noarch
mysql-community-client-5.7.36-1.el7.x86_64

        2、删除上图安装的全部软件例如:

rpm -ev mysql-community-server-5.7.36-1.el7.x86_64 --nodeps

        3、查找相关mysql的文件

# find / -name mysql

# whereis mysql
[root@node04 ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
/usr/bin/mysql
/usr/share/mysql
/etc/selinux/targeted/active/modules/100/mysql
/etc/logrotate.d/mysql
[root@node04 ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

        4、删除全部文件例如:

rm -rf /var/lib/mysql

        5、检查是否删除干净

rpm -qa | grep -i mysql
#如果没有显式则表示卸载完成

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐