【MySQL】在Linux系统环境下的安装教程

一、安装Mysql数据库服务及开发包

1.1 获取mysql官方yum源

wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm

#先选择或创建一个目录,用于存放下载的安装包
[sjl@centos7 mysql]$ wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
--2023-10-14 22:32:45--  http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.198.121.244, 2600:1417:76:79a::1d68, 2600:1417:76:790::1d68
Connecting to repo.mysql.com (repo.mysql.com)|23.198.121.244|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25548 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-10.noarch.rpm’

100%[=============================================================================>] 25,548      17.8KB/s   in 1.4s   

2023-10-14 22:32:47 (17.8 KB/s) - ‘mysql57-community-release-el7-10.noarch.rpm’ saved [25548/25548]

#此时mysql目录下就会出现下载好的安装包
[sjl@centos7 mysql]$ ll
total 28
-rw-r--r-- 1 root root 25548 Apr  7  2017 mysql57-community-release-el7-10.noarch.rpm

1.2 安装mysql官方yum源

sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm

#查看安装好的mysql文件
[sjl@centos7 mysql]$ ls /etc/yum.repos.d/
CentOS-Base.repo      CentOS-SCLo-scl.repo     epel.repo         epel-testing.repo     mysql-community-source.repo
CentOS-Base.repo.bak  CentOS-SCLo-scl-rh.repo  epel.repo.rpmnew  mysql-community.repo

1.3 安装Mysql数据库服务

sudo yum install -y mysql-community-server

1.4 出错解决

如果因为GPG KEY的过期导致安装失败

则执⾏以下指令,然后重新安装

sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

1.5 安装Mysql开发包

sudo yum install -y mysql-community-devel

二、进⾏Mysql配置修改

2.1 启动MySQL服务

sudo systemctl status mysqld

[root@centos7 mysql]# sudo systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-09-19 00:04:25 CST; 3 weeks 4 days ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 13066 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─13066 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Sep 19 00:04:24 centos7.6 systemd[1]: Stopped MySQL Server.
Sep 19 00:04:24 centos7.6 systemd[1]: Starting MySQL Server...
Sep 19 00:04:25 centos7.6 systemd[1]: Started MySQL Server.

注意,如果启动的时候遇到了以下情况,输⼊系统的root管理员密码即可

[sjl@centos7 mysql]$ systemctl start mysqld
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: 
Password: 

2.2 获取Mysql临时密码

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

2.3 设置mysql数据库密码

[sjl@centos7 mysql]$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
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> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
#设置密码长度
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
#设置root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

2.4 配置 '/etc/my.cnf' 字符集(保证数据编码统一,防止出现乱码情况)

sudo vim /etc/my.cnf

打开目标文件后加入以下信息:

[client]

default-character-set=utf8

[mysql]

default-character-set=utf8

[mysqld]

character-set-server=utf8

# 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
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8


#
# 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

然后退出保存。

修改后的字符集:

mysql> show variables like '%chara%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只睡不醒的猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值