Centos7.5无网络安装mysql5.6

Centos7.5无网络安装mysql5.6 rpm 包

关于mysql就不做过多介绍了,话不多说直接开整

下载mysql rpm包

此处为了方便大家笔者提供了官网和百度网盘下载两种方式

官网地址
https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.44-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.44-1.el7.x86_64.rpm
百度网盘
链接:https://pan.baidu.com/s/1hz28fK2jfUXg7CiIQzAb2g 
提取码:gc1n 
复制这段内容后打开百度网盘手机App,操作更方便哦

将下载的rpm包上传到服务器并安装启动

[root@localhost ~]# ll | grep MySQL
-rw-r--r--  1 root root 20460600 7月   5 13:23 MySQL-client-5.6.44-1.el7.x86_64.rpm
-rw-r--r--  1 root root 62822796 7月   5 11:37 MySQL-server-5.6.44-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh MySQL-server-5.6.44-1.el7.x86_64.rpm --force
警告:MySQL-server-5.6.44-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:MySQL-server-5.6.44-1.el7        ################################# [100%]
警告:用户mysql 不存在 - 使用root
警告:群组mysql 不存在 - 使用root
警告:用户mysql 不存在 - 使用root
警告:群组mysql 不存在 - 使用root
....警告可以忽略等到输出配置完成即可

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
只要没有致命错误都可以忽略
[root@localhost ~]# rpm -ivh MySQL-client-5.6.44-1.el7.x86_64.rpm 

启动mysql

[root@localhost ~]# mkdir -pv /var/log/mariadb/				//创建日志文件和路径
mkdir: 已创建目录 "/var/log/mariadb/"
[root@localhost ~]# touch /var/log/mariadb/mariadb.log
[root@localhost ~]# systemctl start mysql
[root@localhost ~]# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysql; bad; vendor preset: disabled)
   Active: active (running) since 五 2019-07-05 15:01:20 CST; 17s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2550 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)
    Tasks: 22
   CGroup: /system.slice/mysql.service
           ├─2558 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
           └─2720 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock

7月 05 15:01:13 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
7月 05 15:01:20 localhost.localdomain mysql[2550]: Starting MySQL...... SUCCESS!
7月 05 15:01:20 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.
[root@localhost ~]# netstat -lnpt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      2720/mysqld         
[root@localhost ~]# ps uax | grep mysql
root       2558  0.0  0.0 115432  1704 ?        S    15:01   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
mysql      2720 14.2 11.6 1302952 449364 ?      Sl   15:01   0:05 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/lib/mysql/localhost.localdomain.p
id --socket=/var/lib/mysql/mysql.sockroot       2768  0.0  0.0 112720   984 pts/0    S+   15:01   0:00 grep --color=auto mysql

mysql启动成功

设置mysql密码并连接

1.安装完成后在家目录下找到这个文件最后就是密码

[root@localhost ~]# cat .mysql_secret 
# The random password set for the root user at Fri Jul  5 14:57:11 2019 (local time): T2GIX_P9rz_hSSjb
[root@localhost ~]# mysql -uroot -pT2GIX_P9rz_hSSjb
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44

Copyright (c) 2000, 2019, 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> use mysql								//默认密码进入sql报错需要设置密码
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> set password = password ('mslinux');					//(‘新密码’)
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;													//刷新权限
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye
[root@localhost ~]# mysql -uroot -pmslinux					//新密码登录测试
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> use mysql						//sql语句测试
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> \q   
Bye

mysql安装完成

2.破解root密码

笔者在Centos7.3环境中遇到安装完成没有.mysql_secret这个文件这个就需要破解密码了。同样该方法也适用密码忘记的情况下使用

修改my.cnf跳过密码验证

[root@localhost ~]# egrep -v '^#|^$' /etc/my.cnf
[mysqld]
skip-grant-tables											//在mysqld下添加跳过认证
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
重启mysql
[root@localhost ~]# systemctl restart mysql
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string=password('mslinux') where user='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye

[root@localhost ~]# mysql				//退出数据库后在使用mysql就无法登陆了,包括使用错误密码
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]# mysql -u root -pmslinux
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> \q
Bye

密码破解成功

注意:此时需要将/etc/my.cnf中 skip-grant-tables注释掉避免以后因为项目等重启数据库后自动跳过认证,修改完成后重启数据库即可。

加油!方法总比问题多!!

你可能感兴趣的:(mysql)