https://www.mysql.com/

https://dev.mysql.com/downloads/ 社区版本
https://downloads.mysql.com/archives/community/

下载linux-generic 
product version 5.7.20
operating system linux -Generic
os Version Linux-Generic(glibc2.12)(x86,64-bit)

Compressed TAR Archive 压缩包 下载这个 
Compressed TAR Archive, Test Suite 测试
TAR 包

https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz


[root@mysql1 ~]# cd /mysql/app/
You have new mail in /var/spool/mail/root
[root@mysql1 app]# ls
lost+found  mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
[root@mysql1 app]# tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 

ln 软链接
ln -s src dest 


[root@mysql1 app]# ls
lost+found                           mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mysql-5.7.20-linux-glibc2.12-x86_64
[root@mysql1 app]# ls mysql-5.7.20-linux-glibc2.12-x86_64
bin  COPYING  docs  include  lib  man  README  share  support-files
[root@mysql1 app]# ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql
[root@mysql1 app]# ls
lost+found  mysql-5.7.20-linux-glibc2.12-x86_64
mysql       mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

[root@mysql1 app]# ll
total 626128
drwx------ 2 root root     16384 May  5 14:14 lost+found
lrwxrwxrwx 1 root root        35 May  5 14:48 mysql -> mysql-5.7.20-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root      4096 May  5 14:48 mysql-5.7.20-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 641127384 May  5 14:47 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz


[root@mysql1 bin]# pwd
/mysql/app/mysql/bin
[root@mysql1 bin]# vim ~/.bash_profile 
PATH=$PATH:/mysql/app/mysql/bin:$HOME/bin
[root@mysql1 bin]# source !$
source ~/.bash_profile
[root@mysql1 bin]# mysql --version
mysql  Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1
[root@mysql1 bin]# ./mysql --version
./mysql  Ver 14.14 Distrib 5.7.20, for linux-glibc2.12 (x86_64) using  EditLine wrapper
You have new mail in /var/spool/mail/root
[root@mysql1 bin]# which mysql
/usr/bin/mysql


删除原来的mysql

[root@mysql1 bin]# rpm -qa|grep mysql
akonadi-mysql-1.9.2-4.el7.x86_64
qt-mysql-4.8.7-9.el7_9.x86_64
[root@mysql1 bin]# rpm -e --nodeps akonadi-mysql-1.9.2-4.el7.x86_64
[root@mysql1 bin]# rpm -e --nodeps qt-mysql-4.8.7-9.el7_9.x86_64   
You have new mail in /var/spool/mail/root
[root@mysql1 bin]# which mysql
/usr/bin/mysql
[root@mysql1 bin]# mysql --version 
mysql  Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1
[root
[root@mysql1 bin]# rpm -qa|grep mariadb 
mariadb-5.5.68-1.el7.x86_64
mariadb-server-5.5.68-1.el7.x86_64
mariadb-libs-5.5.68-1.el7.x86_64
[root@mysql1 bin]# rpm -e --nodeps mariadb-5.5.68-1.el7.x86_64
[root@mysql1 bin]# rpm -e --nodeps mariadb-server-5.5.68-1.el7.x86_64
You have new mail in /var/spool/mail/root
[root@mysql1 bin]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64  
[root@mysql1 bin]# which mysql
/mysql/app/mysql/bin/mysql
[root@mysql1 bin]# source ~/.bash_profile
[root@mysql1 bin]# mysql --version
mysql  Ver 14.14 Distrib 5.7.20, for linux-glibc2.12 (x86_64) using  EditLine wrapper



groupadd mysql
useradd -r -g mysql -s /bin/false mysql

# 修改mysql用户登录的shell
[root@mysql1 bin]# groupadd mysql
groupadd: group 'mysql' already exists
[root@mysql1 bin]# useradd -r -g mysql -s /bin/false mysql
useradd: user 'mysql' already exists
[root@mysql1 bin]# 
[root@mysql1 bin]# 
[root@mysql1 bin]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
[root@mysql1 bin]# cat /etc/passwd|grep mysql
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin

usermod -s /bin/false mysql

[root@mysql1 bin]# cat /etc/passwd|grep mysql
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/bin/false
[root@mysql1 bin]# userdel mysql 删除用户 ,之后重新创建用户,组
[root@mysql1 bin]# cat /etc/passwd|grep mysql

[root@mysql1 bin]# groupadd mysql
[root@mysql1 bin]# useradd -r -g mysql -s /bin/false mysql
[root@mysql1 bin]# !cat
cat /etc/passwd|grep mysql
mysql:x:988:1000::/home/mysql:/bin/false





mkdir -p /mysql/data/3306/data
mkdir -p /mysql/log/3306

chown -R mysql.mysql /mysql

rm -rf  data/3306/data/*
rm -rf  log/3306/*


mysqld --defaults-file=/mysql/data/3306/my.cnf --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data/3306/data



basedir=/mysql/app/mysql
datadir=/mysql/data/3306/data
# Set some defaults
mysqld_pid_file_path=/mysql/data/3306/mysql.pid

if test -z "$basedir"
then
  basedir=/mysql/app/mysql
  bindir=/mysql/app/mysql/bin
  if test -z "$datadir"
  then
    datadir=/mysql/data/3306/data
  fi
  sbindir=/mysql/app/mysql/bin
  libexecdir=/mysql/app/mysql/bin




'start')
    # Start daemon

    # Safeguard (relative paths, core dumps..)
    cd $basedir

    echo $echo_n "Starting MySQL"
    if test -x $bindir/mysqld_safe
    then
      # Give extra arguments to mysqld with the my.cnf file. This script
      # may be overwritten at next upgrade.
      $bindir/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --datadir="$datadir"   --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?


[root@mysql1 support-files]# service mysql start 
Starting MySQL.... SUCCESS! 

[root@mysql1 support-files]# ps -ef|grep mysql
avahi       649      1  0 16:28 ?        00:00:00 avahi-daemon: running [mysql1.local]
root       1748      1  0 16:31 pts/0    00:00:00 /bin/sh /mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --datadir=/mysql/data/3306/data --pid-file=/mysq/data/3306/mysql.pid
mysql      2904   1748  3 16:31 pts/0    00:00:02 /mysql/app/mysql/bin/mysqld --defaults-file=/mysql/data/3306/my.cnf --basedir=/mysql/app/mysql --datadir=/mysql/data/3306/data --plugin-dir=/mysql/app/mysql/lib/plugin --user=mysql --log-error=/mysql/log/3306/mysql1db-error.err --open-files-limit=65536 --pid-file=/mysql/data/3306/mysql.pid --socket=/mysql/data/3306/mysql.sock --port=3306
root       2981   1475  0 16:32 pts/0    00:00:00 grep --color=auto mysql

临时密码
oszw0ZV=ZlC2


[root@mysql1 support-files]# mysql -u root -poszw0ZV=ZlC2
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@mysql1 support-files]# mysql -u root -poszw0ZV=ZlC2 -S /mysql/data/3306/mysql.sock

Server version: 5.7.20-log

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


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



mysql> select host,user from mysql.user;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password = PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant  option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> select host,user from mysql.user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+


密码过期问题
修改my.cnf 添加
skip-grant-tables

进入数据库,修改用户密码,以及过期时间,关闭数据库,将添加的skip-grant-tables注释,启动数据库,重新连接

select * from mysql.user where user='root'\G

password_expired: N # 代表密码没有过期时间,永不过期

use mysql;
update user set password_expired="Y" where user='root';
select * from mysql.user where user='root'\G
password_expired: Y

update user set password_expired="N" where user='root';

启动停止数据库
[root@mysql1 support-files]# service mysql stop 
Shutting down MySQL.. SUCCESS! 
[root@mysql1 support-files]# !ps
ps -ef|grep mysql
avahi       649      1  0 16:28 ?        00:00:00 avahi-daemon: running [mysql1.local]
root       3294   1475  0 16:44 pts/0    00:00:00 grep --color=auto mysql

学习守护进程,那时我开始了解 avahi 守护进程,你能详细解释一下 avahi 守护进程以及为什么 linux 有一个 avahi 用户吗

简而言之:avahi 是一种协议的 Linux 实现,也称为“Rendezvous”或“Bonjour”)。它的目标是让连接到本地网络的设备 广播其IP地址及其功能 。因此,打印机可以不时广播:我的IP是192.168.23.45,我可以使用ipp蛋白打印任何附言文档;NAS 可以说:我的 IP 是 192.168.23.88,我可以流式传输音乐、保存您的 bacups 并充当文件服务器。如果这不是您想在网络上听到的内容,您可以使用标准命令停止/禁用 avahi 守护程序 。但是如果你运行一个杯赛广播守护进程,它将启动 avahi 本身。systemctl ❗ 🔄

Linux通常出于安全原因使用虚构用户,而不是给攻击者任何机会来破解root拥有的进程。因此,您可以看到 or 和 or 用户。由此类非特权用户欠的守护程序使攻击者获得超级用户权限的机会较小。postfixmailpostgresmysql


[root@mysql1 support-files]# id avahi
uid=70(avahi) gid=70(avahi) groups=70(avahi)


[root@mysql1 support-files]# ss -lup        
State      Recv-Q Send-Q Local Address:Port                 Peer Address:Port                
UNCONN     0      0               *:mdns                          *:*                     users:(("avahi-daemon",pid=649,fd=12))
UNCONN     0      0               *:55296                         *:*                     users:(("avahi-daemon",pid=649,fd=13))
UNCONN     0      0      192.168.122.1:domain                        *:*                     users:(("dnsmasq",pid=1139,fd=5))
UNCONN     0      0        *%virbr0:bootps                        *:*                     users:(("dnsmasq",pid=1139,fd=3))
UNCONN     0      0       127.0.0.1:323                           *:*                     users:(("chronyd",pid=704,fd=5))
UNCONN     0      0           [::1]:323                        [::]:*                     users:(("chronyd",pid=704,fd=6))


AFAIK:avahi/bonjour/rendezvous 服务需要所有设备的配合。每个设备每分钟通过几次广播来宣布其服务,而运行/收听 avahi 守护程序的计算机会保留可用服务的集合。如果在计算机上停止 avahi 守护程序,但所有设备都继续播发,则在再次启动 avahi 守护程序后,可以快速重建服务列表。但是,如果您以某种方式强制所有设备停止广播其“会合”信息,即使正在运行的 avahi 守护进程也没有什么可收集的,因此无法进行简单的配置。是的,还有其他一些方法可以保持有关服务的知识,例如端口扫描,本地DNS等。avahi方式非常简单,并且得到了越来越多的支持。决定遵循哪种方式是您的交易。


mysqladmin -u root -proot shutdown -S /mysql/data/3306/mysql.sock 停止数据库

[root@mysql1 support-files]# mysqladmin -u root -proot shutdown -S /mysql/data/3306/mysql.sock
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@mysql1 support-files]# !ps
ps -ef|grep mysql
avahi       649      1  0 16:28 ?        00:00:00 avahi-daemon: running [mysql1.local]
root       4804   1475  0 16:57 pts/0    00:00:00 grep --color=auto mysql
[root@mysql1 support-files]# 


mysql> create database p1 default charset utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

mysql> create user 'p2'@'%' identified by 'p2';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on p1.* to 'p2'@'%' identified by 'p2' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> select host,user from mysql.user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | p2            |
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
5 rows in set (0.00 sec)

mysql> use p1;
Database changed
mysql> create table d1(
    ->  dno int auto_increment primary key,
    ->  name varchar(20));
Query OK, 0 rows affected (0.15 sec)


mysql> insert into d1 values (1,'2');
Query OK, 1 row affected (0.00 sec)


mysql> insert into d1 values (2,'23');
Query OK, 1 row affected (0.00 sec)

mysql> insert into d1 values (3,'23');
Query OK, 1 row affected (0.00 sec)

mysql> select * from d1;
+-----+------+
| dno | name |
+-----+------+
|   1 | 2    |
|   2 | 23   |
|   3 | 23   |
+-----+------+
3 rows in set (0.01 sec)

mysql> drop table d1;
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
Empty set (0.00 sec)