我是靠谱客的博主 帅气台灯,最近开发中收集的这篇文章主要介绍Centos7下载安装配置mysql,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

一,下载mysql

1.在系统中创建mysql文件夹,执行下面的命令,下载官方的 Yum Repository

[root@localhost mysql]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

2.使用yum命令安装

[root@localhost mysql]# yum -y install mysql57-community-release-el7-10.noarch.rpm

 执行结果:

已加载插件:fastestmirror, langpacks
正在检查 mysql57-community-release-el7-10.noarch.rpm: mysql57-community-release-el7-10.noarch
mysql57-community-release-el7-10.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql57-community-release.noarch.0.el7-10 将被 安装
--> 解决依赖关系完成
base/7/x86_64                                            | 3.6 kB     00:00     
extras/7/x86_64                                          | 2.9 kB     00:00     
updates/7/x86_64                                         | 2.9 kB     00:00     

依赖关系解决

================================================================================
 Package           架构   版本   源                                        大小
================================================================================
正在安装:
 mysql57-community-release
                   noarch el7-10 /mysql57-community-release-el7-10.noarch  30 k

事务概要
================================================================================
安装  1 软件包

总计:30 k
安装大小:30 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : mysql57-community-release-el7-10.noarch                     1/1 
  验证中      : mysql57-community-release-el7-10.noarch                     1/1 

已安装:
  mysql57-community-release.noarch 0:el7-10                                     

完毕!
 

 3.安装mysql服务器

[root@localhost mysql]# yum -y install mysql-community-server

结果为:

已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.7.34-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.7.34-1.el7,它被软件包 mysql-community-server-5.7.34-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.34-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.34-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-community-client-5.7.34-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.7.34-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.68-1.el7 将被 取代
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
---> 软件包 mysql-community-libs.x86_64.0.5.7.34-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.5.7.34-1.el7 将被 舍弃
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package                      架构    版本             源                  大小
================================================================================
正在安装:
 mysql-community-libs         x86_64  5.7.34-1.el7     mysql57-community  2.4 M
      替换  mariadb-libs.x86_64 1:5.5.68-1.el7
 mysql-community-libs-compat  x86_64  5.7.34-1.el7     mysql57-community  1.2 M
      替换  mariadb-libs.x86_64 1:5.5.68-1.el7
 mysql-community-server       x86_64  5.7.34-1.el7     mysql57-community  173 M
为依赖而安装:
 mysql-community-client       x86_64  5.7.34-1.el7     mysql57-community   25 M
 mysql-community-common       x86_64  5.7.34-1.el7     mysql57-community  310 k

事务概要
================================================================================
安装  3 软件包 (+2 依赖软件包)

总下载量:203 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.34-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
mysql-community-common-5.7.34-1.el7.x86_64.rpm 的公钥尚未安装
(1/5): mysql-community-common-5.7.34-1.el7.x86_64.rpm      | 310 kB   00:03     
(2/5): mysql-community-libs-5.7.34-1.el7.x86_64.rpm        | 2.4 MB   00:08     
(3/5): mysql-community-libs-compat-5.7.34-1.el7.x86_64.rpm | 1.2 MB   00:03     
(4/5): mysql-community-client-5.7.34-1.el7.x86_64.rpm      |  25 MB   00:37     
(5/5): mysql-community-server-5.7.34-1.el7.x86_64.rpm      | 173 MB   01:02     
--------------------------------------------------------------------------------
总计                                               2.6 MB/s | 203 MB  01:16     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:
 用户ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 指纹       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 软件包     : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : mysql-community-common-5.7.34-1.el7.x86_64                  1/6 
  正在安装    : mysql-community-libs-5.7.34-1.el7.x86_64                    2/6 
  正在安装    : mysql-community-client-5.7.34-1.el7.x86_64                  3/6 
  正在安装    : mysql-community-server-5.7.34-1.el7.x86_64                  4/6 
  正在安装    : mysql-community-libs-compat-5.7.34-1.el7.x86_64             5/6 
  正在删除    : 1:mariadb-libs-5.5.68-1.el7.x86_64                          6/6 
  验证中      : mysql-community-libs-compat-5.7.34-1.el7.x86_64             1/6 
  验证中      : mysql-community-common-5.7.34-1.el7.x86_64                  2/6 
  验证中      : mysql-community-server-5.7.34-1.el7.x86_64                  3/6 
  验证中      : mysql-community-client-5.7.34-1.el7.x86_64                  4/6 
  验证中      : mysql-community-libs-5.7.34-1.el7.x86_64                    5/6 
  验证中      : 1:mariadb-libs-5.5.68-1.el7.x86_64                          6/6 

已安装:
  mysql-community-libs.x86_64 0:5.7.34-1.el7                                    
  mysql-community-libs-compat.x86_64 0:5.7.34-1.el7                             
  mysql-community-server.x86_64 0:5.7.34-1.el7                                  

作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.34-1.el7                                  
  mysql-community-common.x86_64 0:5.7.34-1.el7                                  

替代:
  mariadb-libs.x86_64 1:5.5.68-1.el7                                            

完毕!
 

二、mysql设置

1.启动mysql

[root@localhost mysql]# systemctl start
mysqld.service

执行命令要一段时间,并且没有任何日志输出。

2.查看mysql状态

[root@localhost mysql]# systemctl status mysqld.service

结果:

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2021-07-06 20:49:39 CST; 41s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 13079 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 13023 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 13081 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           └─13081 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/my...

7月 06 20:49:31 localhost.localdomain systemd[1]: Starting MySQL Server...
7月 06 20:49:39 localhost.localdomain systemd[1]: Started MySQL Server.

3.找出mysql密码

[root@localhost mysql]#
grep "password" /var/log/mysqld.log

2021-07-06T12:49:35.670393Z 1 [Note] A temporary password is generated for root@localhost: NV5So-c0>Pgh
末尾的就是密码

4.修改密码

[root@localhost mysql]# mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Hjl@123456';
Query OK, 0 rows affected (0.00 sec)

注意:密码必须要有大小写和特殊字符。

5.开启mysql远程控制

mysql> grant all privileges on *.* to 'root'@'%' identified by 'Hjl@123456' with
grant option;
mysql> flush privileges; 

注意:%代表开发所有IP,可以开放指定的IP地址,如:127.0.0.1

6.给mysql和Tomcat开放防火墙端口

[root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost mysql]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
//重启防火墙
[root@localhost mysql]# firewall-cmd --reload
success

7.设置mysql字符集

[root@localhost mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 5
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> status
--------------
mysql  Ver 14.14 Distrib 5.7.34, for Linux (x86_64) using  EditLine wrapper

Connection id:        5
Current database:    
Current user:        root@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        5.7.34 MySQL Community Server (GPL)
Protocol version:    10
Connection:        Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1

Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /var/lib/mysql/mysql.sock
Uptime:            54 min 49 sec

Threads: 1  Questions: 16  Slow queries: 0  Opens: 112  Flush tables: 1  Open tables: 105  Queries per second avg: 0.004
--------------

发现mysql服务的字符集为Latin1

要去配置文件中修改:

[root@localhost etc]# vi /etc/my.cnf

[client]
default-character-set=utf8

# 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
character-set-server=utf8
collation-server=utf8_general_ci

"my.cnf" 32L, 1056C
主要添加红色部分,主要位置要一致,不然会有错误。

然后重启mysql服务,再次查看:

[root@localhost mysql]# systemctl restart mysqld.service
[root@localhost mysql]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> status
--------------
mysql  Ver 14.14 Distrib 5.7.34, for Linux (x86_64) using  EditLine wrapper

Connection id:        3
Current database:    
Current user:        root@localhost
SSL:            Not in use
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        5.7.34 MySQL Community Server (GPL)
Protocol version:    10
Connection:        Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8

Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /var/lib/mysql/mysql.sock
Uptime:            36 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 105  Flush tables: 1  Open tables: 98  Queries per second avg: 0.13 
--------------

8.mysql常用操作命令:

systemctl restart mysqld.service 重启
systemctl start mysqld.service
开启
systemctl stop mysqld.service
停止

9.在其他机器就可以远程连接mysql了。例如window的cmd中

C:Users13955>mysql -h 192.168.70.149 -P 3306 -u root -p
Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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>

最后

以上就是帅气台灯为你收集整理的Centos7下载安装配置mysql的全部内容,希望文章能够帮你解决Centos7下载安装配置mysql所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(32)

评论列表共有 0 条评论

立即
投稿
返回
顶部