CentOS7 安装Mysql 5.7并解决安装慢的问题

  1. 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql-community-server
yum -y install mysql-community-server

这条命令会执行的特别慢,但是要先执行一次,这样就会在/var/cache/yum/x86_64/7/mysql57-community/packages/ 产生一些你要下载的东西的格式,比如这样的文件:mysql-community-client-5.7.33-1.el7.x86_64.rpm 然后去国内的镜像源去下载,然后删除里面东西,将下载的东西上传到这一块。
国内镜像源地址:

http://uni.mirrors.163.com/mysql/Downloads/

要下载的文件大概为:

mysql-community-client-5.7.33-1.el7.x86_64.rpm
mysql-community-common-5.7.33-1.el7.x86_64.rpm
mysql-community-embedded-5.7.33-1.el7.x86_64.rpm
mysql-community-libs-5.7.33-1.el7.x86_64.rpm
mysql-community-server-5.7.33-1.el7.x86_64.rpm
  1. 再去执行 yum -y install mysql-community-server
    等结束,这样就算是安装成功了!
  2. 配置Mysql
    开启Mysql服务
systemctl start  mysqld

获取临时密码

grep "password" /var/log/mysqld.log

进入数据库

mysql -u root -p

修改密码验证规则

mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

设置简单密码`

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '321123ww';

修改字符编码 vim /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

# 加入下面两行!!!!!
[client]
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

# 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

# 加入下面三行!!!!
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci

完了重启服务:systemctl restart mysqld

查看是否成功:
. 在这里插入图片描述
设置开机自启(没有验证):

systemctl enable mysqld

设置远程连接

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '321123ww' WITH GRANT OPTION;

root 为root用户,3211123ww改为你自己的密码

猜你喜欢

转载自blog.csdn.net/weixin_44061648/article/details/113101008