[root@VM-4-10-centos /]# which mysql
/usr/bin/mysql
[root@VM-4-10-centos /]# mysql --version
mysql Ver 14.14 Distrib 5.7.43, for Linux (x86_64) using EditLine wrapper
[root@VM-4-10-centos /]# rpm -qa | grep mysql | xargs yum -y remove
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Resolving Dependencies
[root@VM-4-10-centos 1Lesson]# yum list | grep mysql
Repository epel is listed more than once in the configuration
mysql57-community-release.noarch el7-9 installed
akonadi-mysql.x86_64 1.9.2-4.el7 os
anope-mysql.x86_64 2.0.14-1.el7 epel
apr-util-mysql.x86_64 1.5.2-6.el7_9.1 updates
calligra-kexi-driver-mysql.x86_64 2.9.10-2.el7 epel
collectd-mysql.x86_64 5.8.1-1.el7 epel
dmlite-plugins-mysql.x86_64 1.15.2-15.el7 epel
dovecot-mysql.x86_64 1:2.2.36-8.el7 os
dpm-copy-server-mysql.x86_64 1.13.0-1.el7 epel
dpm-name-server-mysql.x86_64 1.13.0-1.el7 epel
7. 安装mysql服务
安装前是不存在mysql服务及客户端,以及配置文件的
[root@VM-4-10-centos 1Lesson]# which mysql
/usr/bin/which: no mysql in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/customer/.local/bin:/home/customer/bin)
[root@VM-4-10-centos 1Lesson]# which mysqld
/usr/bin/which: no mysqld in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/customer/.local/bin:/home/customer/bin)
[root@VM-4-10-centos 1Lesson]# ls /etc/my.cf
ls: cannot access /etc/my.cf: No such file or directory
[root@VM-4-10-centos 1Lesson]# yum install -y mysql-community-server
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
安装成功
[root@VM-4-10-centos 1Lesson]# which mysql
/usr/bin/mysql
[root@VM-4-10-centos 1Lesson]# which mysqld
/usr/sbin/mysqld
[root@VM-4-10-centos 1Lesson]# ls /etc/my.cnf
/etc/my.cnf
安装失败跳转第16步
8. 查看配置文件和数据存储位置
查看配置文件/etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[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
[root@VM-4-10-centos 1Lesson]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)
14. 设置开机启动
#开启开机⾃启动
systemctl enable mysqld
systemctl daemon-reload
15. 配置my.cnf
#配置⼀下my.conf,主要是数据库客⼾端和服务器的编码格式
#default-character-set=utf8 ,暂不设置,mysql有bug,汉字不回显
character-set-server=utf8
default-storage-engine=innodb
配置完毕,重启mysql即可
16. 常见问题
安装遇到秘钥过期的问题(服务器是统一环境,一部分秘钥在打包中是过期的):
Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql