mysql5.7安装
环境介绍
- 部署系统:CentOS Linux release 7.7.1908 (Core)
- 部署应用:mysql Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using EditLine wrapper
安装步骤
- 下载 MySQL yum包
## 下载安装包(已存入百度网盘)
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
- 安装MySQL源
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
- 安装MySQL服务端
yum install -y mysql-community-server
- 启动MySQL
systemctl start mysqld.service
这一步会可能会提示:Failed to start mysqld.service,解决方案如下:
安装mariadb和mariadb-server,命令:
yum -y install mariadb mariadb-server
如果在安装mariadb和mariadb-server时提示:
Public key for mysql-community-client-5.7.38-1.el7.x86_64.rpm is not installed Failing package is: mysql-community-client-5.7.38-1.el7.x86_64 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
执行命令:
##原因分析:版本问题 今年2022 明年2023 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- 检查是否启动成功
systemctl status mysqld.service
- 获取临时密码,MySQL5.7为root用户随机生成了一个密码
## 最后的tgjgSfVgC8#a就是临时密码
[root@VM-0-7-centos ~]# grep 'temporary password' /var/log/mysqld.log
2022-05-01T13:15:21.250550Z 1 [Note] A temporary password is generated for root@localhost: tgjgSfVgC8#a
- 通过临时密码登录MySQL,进行修改密码操作
## 使用临时密码登录后,不能进行其他的操作,否则会报错,这时候我们进行修改密码操作
mysql -uroot -p
## 因为MySQL的密码规则需要很复杂,我们一般自己设置的不会设置成这样,所以我们全局修改一下
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
## 修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
## 授权其他机器远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
- 开启开机自启动
systemctl enable mysqld
systemctl daemon-reload
- 设置MySQL的字符集为UTF-8,令其支持中文
vi /etc/my.cnf
##原内容
# read_rnd_buffer_size = 2M
# 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
## 改成如下样子
# read_rnd_buffer_size = 2M
# 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
[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
default-storage-engine=INNODB
character_set_server=utf8
# 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
##重启一下MySQL,令配置生效
service mysqld restart
-
数据库的操作
-
查看mysql是否启动:service mysqld status
-
启动mysql:service mysqld start
-
停止mysql:service mysqld stop
-
重启mysql:service mysqld restart
-
安装参考:
https://www.cnblogs.com/wangjunjiehome/p/15534102.html
问题参考:
1、https://blog.csdn.net/miaodichiyou/article/details/99289160
2、https://blog.csdn.net/Jaeger_Java/article/details/124425409