Linux基础学习七:mysql的安装和配置教程

 MySQL的安装

 yum安装

下载并安装MySQL5.7的yum源

[root@localhost ~]# wget -P /tmp https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

[root@localhost ~]# cd /tmp
[root@localhost tmp]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm 
警告:mysql57-community-release-el7-9.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql57-community-release-el7-9  ################################# [100%]

通过yum安装MySQL5.7  

[root@localhost tmp]# yum install -y mysql-server
需要等待较长时间...

 启动MySQL

查看mysql是否启动
[root@localhost tmp]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
           
启动mysql
[root@localhost tmp]# systemctl start mysqld

查看mysql是否启动
[root@localhost tmp]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2020-05-30 18:28:14 CST; 2min 2s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 37102 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 37048 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 37105 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─37105 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

初始化MySQL  

查看初始随机密码
[root@localhost tmp]# head -n 10 /var/log/mysqld.log 
2020-05-30T10:28:09.210385Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-30T10:28:09.906316Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-30T10:28:10.001119Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-30T10:28:10.064286Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4245a568-a260-11ea-85b9-000c290150c5.
2020-05-30T10:28:10.067028Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-30T10:28:11.461525Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-30T10:28:11.839011Z 1 [Note] A temporary password is generated for root@localhost: o3DIit9dDr%n
2020-05-30T10:28:14.443528Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

登录mysql,并修改root账号的密码
[root@localhost mysql-rpm-5.7.29]# mysql -u root -p
Enter password:粘贴随机初始密码

修改密码,注意:默认密码检查策略比较严格,必须定义如下类似密码
mysql> alter user 'root'@'localhost' identified by '$Baiduroot2002';

修改为简单密码:
修改密码检查策略

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

修改root为简单密码
mysql> alter user root@'localhost' identified by '123456';

设置root允许远程登录
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;//一定要刷新操作

 

rpm包安装

 

准备工作:将 mysql-rpm-5.7.29 文件夹整体上传到 /tmp 下。

1. 卸载CentOS内置的mariadb
 

[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
注意:不同的电脑查询的软件名略有差异,下一步一定要根据刚才查询的结果进行卸载(对刚才的结果复制粘贴)
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64

2. 通过安装vim,安装vim和MySQL通用的依赖

[root@localhost ~]# yum install -y vim

 3.进入到安装包目录,按顺序安装rpm包

[root@localhost ~]# cd /tmp/mysql-rpm-5.7.29/
[root@localhost mysql-rpm-5.7.29]# rpm -ivh 1*.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:net-tools-2.0-0.22.20131004git.el################################# [100%]
   
[root@localhost mysql-rpm-5.7.29]# rpm -ivh 2*.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:perl-Net-Daemon-0.48-5.el7       ################################# [ 14%]
   2:perl-Data-Dumper-2.145-3.el7     ################################# [ 29%]
   3:perl-Compress-Raw-Zlib-1:2.061-4.################################# [ 43%]
   4:perl-Compress-Raw-Bzip2-2.061-3.e################################# [ 57%]
   5:perl-IO-Compress-2.061-2.el7     ################################# [ 71%]
   6:perl-PlRPC-0.2020-14.el7         ################################# [ 86%]
   7:perl-DBI-1.627-4.el7             ################################# [100%]
   
[root@localhost mysql-rpm-5.7.29]# rpm -ivh 3*.rpm
警告:3 mysql-community-client-5.7.29-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.29-1.e################################# [ 25%]
   2:mysql-community-libs-5.7.29-1.el7################################# [ 50%]
   3:mysql-community-client-5.7.29-1.e################################# [ 75%]
   4:mysql-community-server-5.7.29-1.e################################# [100%]

 4.启动MySQL

查看mysql是否启动
[root@localhost mysql-rpm-5.7.29]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html

启动mysql
[root@localhost mysql-rpm-5.7.29]# systemctl start mysqld

查看mysql是否启动
[root@localhost mysql-rpm-5.7.29]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2020-05-30 18:06:02 CST; 10s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 36957 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 36904 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 36960 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─36960 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

5.初始化MySQL

 查看初始随机密码
[root@localhost mysql-rpm-5.7.29]# head -n 10 /var/log/mysqld.log 
2020-05-30T10:05:57.592355Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-30T10:05:58.055873Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-30T10:05:58.194923Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-30T10:05:58.336295Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 288015b5-a25d-11ea-a36c-000c29b18b53.
2020-05-30T10:05:58.338480Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-30T10:05:58.912744Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-30T10:05:59.122501Z 1 [Note] A temporary password is generated for root@localhost: fcq0W%WawxwR
2020-05-30T10:06:02.023609Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-30T10:06:02.039831Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.29) starting as process 36960 ...
2020-05-30T10:06:02.051955Z 0 [Note] InnoDB: PUNCH HOLE support available

登录mysql,并修改root账号的密码
[root@localhost mysql-rpm-5.7.29]# mysql -u root -p
Enter password:粘贴随机初始密码

修改密码,注意:默认密码检查策略比较严格,必须定义如下类似密码
mysql> alter user 'root'@'localhost' identified by '$Baiduroot2002';

修改为简单密码:
修改密码检查策略

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

修改root为简单密码
mysql> alter user root@'localhost' identified by '123456';

设置root允许远程登录
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;//一定要刷新操作

Navicat连接MySQL

  1. 关闭linux虚拟机的防火墙

    systemctl stop firewalld
  2. 使用Navicat连接虚拟机中的MySQL

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值