#在看看能不能正常⼯作[sz@VM-0-3-centos 9.9]$ yum list |grep mysql
Repository epel is listed more than once in the configuration
mysql57-community-release.noarch el7-10 installed
akonadi-mysql.x86_64 1.9.2-4.el7 base
anope-mysql.x86_64 2.0.9-3.el7 epel
apr-util-mysql.x86_64 1.5.2-6.el7 base
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.14.2-1.el7 epel
dovecot-mysql.x86_64 1:2.2.36-8.el7 base
7. 安装mysql服务
[sz@VM-0-3-centos 9.9]$ sudo yum install -y mysql-community-server
[sudo] password for whb:
Loaded plugins: aliases, auto-update-debuginfo, fastestmirror, protectbase
Repository epel is listed more than once in the configuration
...
Installing : mysql-community-common-5.7.33-1.el7.x86_64 #公共模块
Installing : mysql-community-libs-5.7.33-1.el7.x86_64 #库
Installing : mysql-community-client-5.7.33-1.el7.x86_64 #客⼾端
Installing : mysql-community-server-5.7.33-1.el7.x86_64 #服务器... #安装了服务和客⼾端# 如果报错了,看第16步《常⻅问题》
8. 查看配置⽂件和数据存储位置
[sz@VM-0-3-centos 9.9]$ ls /etc/my.cnf
/etc/my.cnf
[sz@VM-0-3-centos 9.9]$ sudols /var/lib/mysql
.....
9. 启动服务
[sz@VM-0-3-centos 9.9]$ systemctl start mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password:
==== AUTHENTICATION COMPLETE ===
[root@bite-alicloud mysql]# vim /etc/my.cnf # 打开mysql配置⽂件
在[mysqld]最后⼀栏配置(不知道是什么,就放在配置⽂件最后) 加⼊: skip-grant-tables 选项,
并保存退出
[root@bite-alicloud mysql]# systemctl restart mysqld # 重启mysql服务# 登陆成功[root@bite-alicloud mysql]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41 MySQL Community Server (GPL)
Copyright (c)2000, 2023, Oracle and/or its affiliates.
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>
#配置⼀下my.conf,主要是数据库客⼾端和服务器的编码格式[sz@VM-0-3-centos 9.9]$ cat /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[mysql]#default-character-set=utf8 ,暂不设置,mysql有bug,汉字不回显[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 = 2Mport=3306datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
og-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server=utf8
default-storage-engine=innodb
# 配置完毕,重启mysql即可
16. 常见问题
mysql 已经配置了客⼾端服务器utf8编码,但是⽆法输⼊中⽂
确保您在终端命令⾏中可以输⼊中⽂
[whb@VM-0-3-centos ~]$ env|grepLANGLANG=en_US.utf8
安装遇到秘钥过期的问题:
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
解决⽅案:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022