锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

MySQL系列数据库的安装和基本的使用方法笔记(MySQL,MariaDB)

时间:2023-06-19 21:07:00 jst连接器07p

MySQL安装系列数据库数据库的基本方法(MySQL,MariaDB)

MySQL介绍

创始人Michael Widenius

历史

1996/xx MySQL 1.0 1996/10 MySQL 3.11.1 1999/xx MySQL AB公司,瑞典 2001/xx InnoDB开发 2003/xx MySQL 5.0,提供识图 存储过程等 2005/xx Oracle收购InnoDB 2008/01 Sun收购MySQL AB公司,10以美元 2008/11 MySQL 5.1 2009/04 Oracle收购Sun,74亿美元 2009/xx Monty成立MariaDB 2010/12 MySQL 5.5,InnoDB成MySQL默认存储引擎  

MySQL系列数据库

  • MySQL
    • https://www.mysql.com/
    • 商业版
    • 社区版GPL(5.0,5.1,5.5,5.6,5.7)
  • mariaDB
    • Foundation版本(10.2-10.8)
      • https://mariadb.org/
    • Corporation版
      • https://mariadb.com/
      • 社区版:MariaDB Community
      • 企业版:MariaDB Enterprise
      • 云版:SkySQL(DBaaS:DB as a Services)
  • percona Server(这不是专门做的MySQL还有其他的,比如MariaDB,PostgreSQL等)
    • https://www.percona.com/
    • 只提供版本8Linux下载
    • https://www.percona.com/downloads/Percona-Server-LATEST/

数据库对比

https://db-engines.com/en/system/MariaDB;MySQL;Percona Server for MySQL

MySQL特性

  • 开源

  • 插件式存储引擎,又称表型,存储管理器有多个实现版本,功能和特性略有差异,5.5开始InnoDB是默认引擎

    MySQL  -- Other MyISAM -- Aria InnoDB -- XtraDB(MariaDB) 
  • 单进程,多线程

  • 扩展,特性

  • 多测试组件

MySQL安装系列数据库

安装方法和版本

安装方法

  • 包管理器(yum,rpm等)
  • 源码编译
  • 二进制文件(免安装版)

各种版本

  • OS版本
    • Win
    • MacOS
    • Linux
      • RHEL
        • 6
        • 7
        • 8
  • 软件版本
    • MariaDB
      • 10.x
    • MySQL
      • 5.6
      • 8.x

包管理器(yum,rpm等)

相关URL

  • MySQL
    • https://downloads.mysql.com/archives/community/
    • 其他镜像
  • MariaDB
    • https://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb//mariadb-10.6.5/bintar-linux-systemd-x86_64/mariadb-10.6.5-linux-systemd-x86_64.tar.gz
# 默认yum源头上的安装包 [root@C84MySQL8 ~]# yum info mysql-server Name         : mysql-server Version      : 8.0.26  [root@C84MySQL8 ~]# yum info mariadb-server Name         : mariadb-server Version      : 10.3.28  [root@C84MySQL8 ~]# yum info mariadb.x86_64 Name         : mariadb Version      : 10.3.28  # CentOS7 不提供MySQL? [root@c79maria10 ~]# yum info mysql-community-server Error: No matching Packages to list  [root@c79maria10 ~]# yum info mysql Error: No matching Packages to list  [root@c79maria10 ~]# yum info mariadb Name        : mariadb Version     : 5.5.68 Summary     : A community developed branch of MySQL  [root@c79maria10 ~]# yum info mariadb-server Name        : mariadb-server Version     : 5.5.68 Summary     : The MariaDB server and related files  
# DVD在光盘上安装rpm包(需要完整版DVD才有,没有数据库的迷你) [root@C84MySQL8 ~]# ls /mnt/AppStream/Packages/ | grep mysql-server mysql-server-8.0.21-1.module_el8.2.0 493 63b41e36.x86_64.rpm  [root@C84MySQL8 ~]# ls /mnt/AppStream/Packages/ | grep mariadb-server mariadb-server-10.3.27-3.module_el8.3.0 599 c587b2e7.x86_64.rpm mariadb-server-10.5.9-1.module_el8.4.0 801 647c4915.x86_64.rpm  

CentOS7安装MySQL 5.7(rpm)官方下载

URL

# https://downloads.mysql.com/archives/community/ # 选择RPM Bundle包装所有相关包 # Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit), RPM Bundle # (mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar) # MD5: 99c03ce2fe9c57d3f76f59f7211be900 # 下载连接 # https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar 

下载

[root@c79maria10 ~]# mkdir mysql57 [root@c79maria10 ~]# cd mysql57/ [root@c79maria10 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar --2021-12-23 21:02:40--  ttps://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
Resolving downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar [following]
--2021-12-23 21:02:41--  https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
Resolving cdn.mysql.com (cdn.mysql.com)... 104.93.8.235
Connecting to cdn.mysql.com (cdn.mysql.com)|104.93.8.235|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 545617920 (520M) [application/x-tar]
Saving to: ‘mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar’

[root@c79maria10 mysql57]# tar -xf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
[root@c79maria10 mysql57]# ls
mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.35-1.el7.x86_64.rpm
mysql-community-common-5.7.35-1.el7.x86_64.rpm
mysql-community-devel-5.7.35-1.el7.x86_64.rpm
mysql-community-embedded-5.7.35-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.35-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.35-1.el7.x86_64.rpm
mysql-community-libs-5.7.35-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.35-1.el7.x86_64.rpm
mysql-community-server-5.7.35-1.el7.x86_64.rpm
mysql-community-test-5.7.35-1.el7.x86_64.rpm

卸载冲突包,安装前提包

error: Failed dependencies:
        mariadb-libs is obsoleted by mysql-community-libs-5.7.35-1.el7.x86_64
        mariadb-libs is obsoleted by mysql-community-libs-compat-5.7.35-1.el7.x86_64

[root@c79maria10 mysql57]# rpm -evh mariadb-libs
error: Failed dependencies:
        libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
        libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64

[root@c79maria10 mysql57]# rpm -evh postfix
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:postfix-2:2.10.1-9.el7           ################################# [100%]
[root@c79maria10 mysql57]# rpm -evh mariadb-libs
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:mariadb-libs-1:5.5.68-1.el7      ################################# [100%]

[root@c79maria10 mysql57]# yum -y install libaio perl-Data-Dumper perl-JSON net-tools

# 全部安装的话
[root@c79maria10 mysql57]# rpm -ivh ./*.rpm
warning: ./mysql-community-client-5.7.35-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.35-1.e################################# [ 10%]
   2:mysql-community-libs-5.7.35-1.el7################################# [ 20%]
   3:mysql-community-client-5.7.35-1.e################################# [ 30%]
   4:mysql-community-server-5.7.35-1.e################################# [ 40%]
   5:mysql-community-devel-5.7.35-1.el################################# [ 50%]
   6:mysql-community-embedded-5.7.35-1################################# [ 60%]
   7:mysql-community-embedded-devel-5.################################# [ 70%]
   8:mysql-community-test-5.7.35-1.el7################################# [ 80%]
   9:mysql-community-libs-compat-5.7.3################################# [ 90%]
  10:mysql-community-embedded-compat-5################################# [100%]

# 卸载
[root@c79maria10 mysql57]# rpm -evh $(rpm -qa | grep mysql)
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:mysql-community-embedded-devel-5.################################# [ 10%]
   2:mysql-community-devel-5.7.35-1.el################################# [ 20%]
   3:mysql-community-embedded-5.7.35-1################################# [ 30%]
   4:mysql-community-embedded-compat-5################################# [ 40%]
   5:mysql-community-test-5.7.35-1.el7################################# [ 50%]
   6:mysql-community-server-5.7.35-1.e################################# [ 60%]
   7:mysql-community-client-5.7.35-1.e################################# [ 70%]
   8:mysql-community-libs-compat-5.7.3################################# [ 80%]
   9:mysql-community-libs-5.7.35-1.el7################################# [ 90%]
  10:mysql-community-common-5.7.35-1.e################################# [100%]

# 只安装客户端和服务器以及依赖包
# server依赖,common和client,client依赖common和common-libs(其他的系统的许多基础性包)

[root@c79maria10 mysql57]# rpm -q --requires mysql-community-server-5.7.35-1.el7 | grep mysql
config(mysql-community-server) = 5.7.35-1.el7
mysql-community-client(x86-64) >= 5.7.9
mysql-community-common(x86-64) = 5.7.35-1.el7

[root@c79maria10 mysql57]# rpm -q --requires mysql-community-client | grep mysql
mysql-community-libs(x86-64) >= 5.7.9

[root@c79maria10 mysql57]# rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm
[root@c79maria10 mysql57]# rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm
[root@c79maria10 mysql57]# rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
[root@c79maria10 mysql57]# rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm

安装路径,相关文件


[root@c79maria10 mysql57]# rpm -ql $(rpm -qa | grep mysql) | grep -v -e /usr/share/ -e /usr/lib64/
/usr/bin/mysql
/usr/bin/mysql_config_editor
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqlimport
/usr/bin/mysqlpump
/usr/bin/mysqlshow
/usr/bin/mysqlslap
/etc/ld.so.conf.d/mysql-x86_64.conf
/etc/logrotate.d/mysql
/etc/my.cnf
/etc/my.cnf.d
/usr/bin/innochecksum
/usr/bin/lz4_decompress
/usr/bin/my_print_defaults
/usr/bin/myisam_ftdump
/usr/bin/myisamchk
/usr/bin/myisamlog
/usr/bin/myisampack
/usr/bin/mysql_install_db
/usr/bin/mysql_plugin
/usr/bin/mysql_secure_installation
/usr/bin/mysql_ssl_rsa_setup
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_upgrade
/usr/bin/mysqld_pre_systemd
/usr/bin/mysqldumpslow
/usr/bin/perror
/usr/bin/replace
/usr/bin/resolve_stack_dump
/usr/bin/resolveip
/usr/bin/zlib_decompress
/usr/lib/systemd/system/mysqld.service
/usr/lib/systemd/system/mysqld@.service
/usr/lib/tmpfiles.d/mysql.conf
/usr/sbin/mysqld
/usr/sbin/mysqld-debug
/var/lib/mysql
/var/lib/mysql-files
/var/lib/mysql-keyring
/var/run/mysqld

启动MySQL服务器

[root@c79maria10 ~]# systemctl start mysqld

[root@c79maria10 ~]# ss -ntlp | grep mysql
LISTEN     0      80        [::]:3306                  [::]:*                   users:(("mysqld",pid=2015,fd=21))

登录

[root@c79maria10 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@c79maria10 ~]# grep password /var/log/mysqld.log
2021-12-23T12:28:26.345720Z 1 [Note] A temporary password is generated for root@localhost: HyWPf,Sgz2*a
2021-12-23T12:29:52.814038Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)

# 修改初始密码,用初始密码登录后修改(破解密码,或者忘记密码怎么办▲▲)
[root@c79maria10 ~]# mysql -uroot -p'HyWPf,Sgz2*a'
mysql> status
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by 'MySQL123!';
Query OK, 0 rows affected (0.00 sec)

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.7.35, 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.35
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:                 3 min 37 sec

Threads: 1  Questions: 7  Slow queries: 0  Opens: 106  Flush tables: 1  Open tables: 99  Queries per second avg: 0.032
--------------


[root@c79maria10 ~]# mysql -uroot -p'MySQL123!'

# 修改密码2(怎么使用ssl,怎么设置命令不记录password之类的命令?▲▲)
[root@c79maria10 ~]# mysqladmin -uroot -p'MySQL123!' password 'MySQL124!'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

CentOS7安装MySQL 5.7(yum)清华镜像

卸载上面安装的MySQL(还需要卸载数据,日志文件等)

[root@c79maria10 ~]# rpm -qa | grep mysql
mysql-community-common-5.7.35-1.el7.x86_64
mysql-community-client-5.7.35-1.el7.x86_64
mysql-community-libs-5.7.35-1.el7.x86_64
mysql-community-server-5.7.35-1.el7.x86_64
[root@c79maria10 ~]# rpm -evh $(rpm -qa | grep mysql)
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:mysql-community-server-5.7.35-1.e################################# [ 25%]
   2:mysql-community-client-5.7.35-1.e################################# [ 50%]
   3:mysql-community-libs-5.7.35-1.el7################################# [ 75%]
   4:mysql-community-common-5.7.35-1.e################################# [100%]

配置 yum源

# URL
# https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/

[root@c79maria10 ~]# tee /etc/yum.repos.d/mysql.tsinghua.repo << EOL
> [mysql]
> name=mysql5.7
> baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
> gpgcheck=0
> enabled=1
> EOL
[mysql]
name=mysql5.7
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
gpgcheck=0
enabled=1
[root@c79maria10 ~]# yum repolist
mysql                                                  | 2.9 kB  00:00:00
mysql/primary_db                                       | 302 kB  00:00:03
repo id                    repo name                               status
base/7/x86_64              CentOS-7 - Base                         10,072
extras/7/x86_64            CentOS-7 - Extras                          500
mysql                      mysql5.7                                   544
updates/7/x86_64           CentOS-7 - Updates                       3,242
repolist: 14,358

安装

[root@c79maria10 ~]# yum -y install mysql-community-server
Warning: RPMDB altered outside of yum.

  Installing : mysql-community-common-5.7.36-1.el7.x86_64        1/4
  Installing : mysql-community-libs-5.7.36-1.el7.x86_64          2/4
  Installing : mysql-community-client-5.7.36-1.el7.x86_64        3/4
  Installing : mysql-community-server-5.7.36-1.el7.x86_64 [### ] 4/4

[root@c79maria10 ~]# rpm -qa | grep mysql
mysql-community-common-5.7.36-1.el7.x86_64
mysql-community-client-5.7.36-1.el7.x86_64
mysql-community-libs-5.7.36-1.el7.x86_64
mysql-community-server-5.7.36-1.el7.x86_64

[root@c79maria10 ~]# systemctl start mysqld

[root@c79maria10 ~]# ss -ntlp | grep mysql
LISTEN     0      80        [::]:3306                  [::]:*                   users:(("mysqld",pid=2274,fd=22))

修改初期密码

# 没有产生初始密码怎办?▲▲安装后有个初始化,话生成数据文件,日志等。如果直接用其他数据文件的话,root密码如何设置??
[root@c79maria10 ~]# grep password /var/log/mysqld.log

[root@c79maria10 ~]# grep password /var/log/mysqld.log
2021-12-23T12:28:26.345720Z 1 [Note] A temporary password is generated for root@localhost: HyWPf,Sgz2*a
2021-12-23T12:29:52.814038Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2021-12-23T12:35:59.095055Z 0 [Note] Shutting down plugin 'validate_password'
2021-12-23T12:36:00.819807Z 0 [Note] Shutting down plugin 'sha256_password'
2021-12-23T12:36:00.819810Z 0 [Note] Shutting down plugin 'mysql_native_password'
2021-12-23T12:44:34.068069Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2021-12-23T12:45:21.540152Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-12-23T12:45:45.788246Z 4 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-12-23T12:47:00.441677Z 5 [Note] Access denied for user 'root'@'localhost' (using password: NO)

# 旧的数据库文件,日志没有删除,所以安装后没有生成新的密码

[root@c79maria10 ~]# mysql -uroot -p'MySQL124!'
mysql: [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 7
Server version: 5.7.36 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>

CentOS7安装MariaDB 10.6(yum)官方镜像

卸载掉MySQL

[root@c79maria10 ~]# systemctl stop mysqld
[root@c79maria10 ~]# rpm -evh $(rpm -qa | grep mysql)
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:mysql-community-server-5.7.36-1.e################################# [ 25%]
   2:mysql-community-client-5.7.36-1.e################################# [ 50%]
   3:mysql-community-libs-5.7.36-1.el7################################# [ 75%]
   4:mysql-community-common-5.7.36-1.e################################# [100%]

# yum源无效化

[root@c79maria10 ~]# mv /etc/yum.repos.d/mysql.tsinghua.repo /etc/yum.repos.d/mysql.tsinghua.repo.bak

配置yum源,MariaDB URL

# https://mariadb.org/download/?t=repo-config&d=CentOS+7+%28x86_64%29&v=10.6&r_m=yamagata-university

[root@c79maria10 ~]# cat > /etc/yum.repos.d/mariadb10.6.repo << EOL
> # MariaDB 10.6 CentOS repository list - created 2021-12-23 12:53 UTC
> # https://mariadb.org/download/
> [mariadb]
> name = MariaDB
> baseurl = https://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/yum/10.6/centos7-amd64
> gpgkey=https://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/yum/RPM-GPG-KEY-MariaDB
> gpgcheck=1
> EOL

[root@c79maria10 ~]# yum repolist              
mariadb                                                | 3.4 kB  00:00:00
(1/2): mariadb/updateinfo                              | 5.4 kB  00:00:00
(2/2): mariadb/primary_db                              |  67 kB  00:00:00
repo id                     repo name                              status
base/7/x86_64               CentOS-7 - Base                        10,072
extras/7/x86_64             CentOS-7 - Extras                         500
mariadb                     MariaDB                                    93
updates/7/x86_64            CentOS-7 - Updates                      3,242
repolist: 13,907                                  


安装

[root@c79maria10 ~]# yum -y install MariaDB-server MariaDB-client

Install  2 Packages (+15 Dependent packages)
Total download size: 54 M
Installed size: 225 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mariadb/packages/MariaDB-common-10.6.5-1.el7.centos.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 1bb943db: NOKEY

Warning: RPMDB altered outside of yum.


[root@c79maria10 ~]# rpm -ql $(rpm -qa | grep MariaDB) | grep -v -e /usr/share -e /usr/lib64 -e /usr/lib
/etc/my.cnf
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf
/usr/bin/mariadb
/usr/bin/mariadb-access
/usr/bin/mariadb-admin
/usr/bin/mariadb-binlog
/usr/bin/mariadb-check
/usr/bin/mariadb-conv
/usr/bin/mariadb-convert-table-format
/usr/bin/mariadb-dump
/usr/bin/mariadb-dumpslow
/usr/bin/mariadb-embedded
/usr/bin/mariadb-find-rows
/usr/bin/mariadb-hotcopy
/usr/bin/mariadb-import
/usr/bin/mariadb-plugin
/usr/bin/mariadb-secure-installation
/usr/bin/mariadb-setpermission
/usr/bin/mariadb-show
/usr/bin/mariadb-slap
/usr/bin/mariadb-tzinfo-to-sql
/usr/bin/mariadb-waitpid
/usr/bin/msql2mysql
/usr/bin/my_print_defaults
/usr/bin/mysql
/usr/bin/mysql_embedded
/usr/bin/mysql_find_rows
/usr/bin/mysql_plugin
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_waitpid
/usr/bin/mysqlaccess
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqlimport
/usr/bin/mysqlshow
/usr/bin/mysqlslap
/usr/bin/mytop
/usr/bin/replace
/etc/logrotate.d/mysql
/etc/my.cnf.d
/etc/my.cnf.d/enable_encryption.preset
/etc/my.cnf.d/server.cnf
/etc/my.cnf.d/spider.cnf
/etc/security/user_map.conf
/lib64/security/pam_user_map.so
/usr/bin/aria_chk
/usr/bin/aria_dump_log
/usr/bin/aria_ftdump
/usr/bin/aria_pack
/usr/bin/aria_read_log
/usr/bin/galera_new_cluster
/usr/bin/galera_recovery
/usr/bin/innochecksum
/usr/bin/mariadb-fix-extensions
/usr/bin/mariadb-install-db
/usr/bin/mariadb-service-convert
/usr/bin/mariadb-upgrade
/usr/bin/mariadbd-multi
/usr/bin/mariadbd-safe
/usr/bin/mariadbd-safe-helper
/usr/bin/myisam_ftdump
/usr/bin/myisamchk
/usr/bin/myisamlog
/usr/bin/myisampack
/usr/bin/mysql_fix_extensions
/usr/bin/mysql_install_db
/usr/bin/mysql_upgrade
/usr/bin/mysqld_multi
/usr/bin/mysqld_safe
/usr/bin/mysqld_safe_helper
/usr/bin/perror
/usr/bin/resolve_stack_dump
/usr/bin/resolveip
/usr/bin/wsrep_sst_common
/usr/bin/wsrep_sst_mariabackup
/usr/bin/wsrep_sst_mysqldump
/usr/bin/wsrep_sst_rsync
/usr/bin/wsrep_sst_rsync_wan
/usr/sbin/mariadbd
/usr/sbin/mysqld
/usr/sbin/rcmysql

[root@c79maria10 ~]# rpm -qf /usr/bin/mysql
MariaDB-client-10.6.5-1.el7.centos.x86_64

启动(一启动就有2个监听,一个IPV6?)

[root@c79maria10 ~]# systemctl start mariadb
[root@c79maria10 ~]# ss -ntlp | grep mariadb
LISTEN     0      80           *:3306                     *:*                   users:(("mariadbd",pid=2671,fd=20))
LISTEN     0      80        [::]:3306                  [::]:*                   users:(("mariadbd",pid=2671,fd=22))

登录

# 和MySQL兼容,连数据文件 都是用一样的默认的,所以,旧的配置留了下来的。密码什么的
[root@c79maria10 ~]# mysql -uroot -p'MySQL124!'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.6.5-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

清除旧MySQL配置,重新安装

[root@c79maria10 ~]# systemctl stop mariadb
[root@c79maria10 ~]# mv /var/lib/mysql /var/lib/mysql.bak


[root@c79maria10 ~]# rpm -evh $(rpm -qa | grep MariaDB)
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:MariaDB-server-10.6.5-1.el7.cento################################# [ 25%]
   2:MariaDB-client-10.6.5-1.el7.cento################################# [ 50%]
   3:MariaDB-compat-10.6.5-1.el7.cento################################# [ 75%]
   4:MariaDB-common-10.6.5-1.el7.cento################################# [100%]

[root@c79maria10 ~]# yum -y install MariaDB-server MariaDB-client

[root@c79maria10 ~]# systemctl start mariadb
[root@c79maria10 ~]# mysql	# 全新安装的话,没有密码直接进入。yum安装的没有过程的日志
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.5-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> status
--------------
mysql  Ver 15.1 Distrib 10.6.5-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:          4
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.6.5-MariaDB MariaDB Server
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8mb3
Conn.  characterset:    utf8mb3
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 1 min 23 sec

Threads: 1  Questions: 6  Slow queries: 0  Opens: 17  Open tables: 10  Queries per second avg: 0.072
--------------


[root@c79maria10 ~]# ls /var/lib | grep mysql
mysql
mysql.bak
[root@c79maria10 ~]# ls /var/lib | grep maria
[root@c79maria10 ~]#

[root@c79maria10 ~]# ls /var/lib/mysql
aria_log.00000001  c79maria10.pid    ib_buffer_pool  ib_logfile0  multi-master.info  mysql.sock          sys
aria_log_control   ddl_recovery.log  ibdata1         ibtmp1       mysql              performance_schema  test

CentOS8安装MySQL 8.0(rpm)官方下载

连接

# https://downloads.mysql.com/archives/community/
# 下载RPM Bundle
# Red Hat Enterprise Linux 8 / Oracle Linux 8 (x86, 64-bit), RPM Bundle
# (mysql-8.0.24-1.el8.x86_64.rpm-bundle.tar)
# MD5: dc2783e841dc81660e05de70f8f29bfd

下载

[root@C84MySQL8 ~]# mkdir mysql8
[root@C84MySQL8 ~]# cd mysql8/

[root@C84MySQL8 mysql8]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.24-1.el8.x86_64.rpm-bundle.tar
--2021-12-23 22:30:10--  https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.24-1.el8.x86_64.rpm-bundle.tar
Resolving downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.24-1.el8.x86_64.rpm-bundle.tar [following]
--2021-12-23 22:30:11--  https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.24-1.el8.x86_64.rpm-bundle.tar
Resolving cdn.mysql.com (cdn.mysql.com)... 104.93.8.235
Connecting to cdn.mysql.com (cdn.mysql.com)|104.93.8.235|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 765358080 (730M) [application/x-tar]
Saving to: ‘mysql-8.0.24-1.el8.x86_64.rpm-bundle.tar’

4-1.el8.x86_64.rpm-bundle.tar    3%[>                                                  ]  25.87M  2.59MB/s    eta 4m 44s

[root@C84MySQL8 mysql8]# tar -xf mysql-8.0.24-1.el8.x86_64.rpm-bundle.tar

卸载冲突,安装依赖包

# 这里暂时没有冲突
[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-server-8.0.24-1.el8.x86_64.rpm
warning: mysql-community-server-8.0.24-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        /usr/bin/perl is needed by mysql-community-server-8.0.24-1.el8.x86_64
        libaio.so.1()(64bit) is needed by mysql-community-server-8.0.24-1.el8.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.24-1.el8.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.24-1.el8.x86_64
        mysql-community-client(x86-64) >= 8.0.11 is needed by mysql-community-server-8.0.24-1.el8.x86_64
        mysql-community-common(x86-64) = 8.0.24-1.el8 is needed by mysql-community-server-8.0.24-1.el8.x86_64
        net-tools is needed by mysql-community-server-8.0.24-1.el8.x86_64

[root@C84MySQL8 mysql8]# yum -y install net-tools libaio perl

[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-common-8.0.24-1.el8.x86_64.rpm
warning: mysql-community-common-8.0.24-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.0.24-1.e################################# [100%]


[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-client-8.0.24-1.el8.x86_64.rpm
warning: mysql-community-client-8.0.24-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        mysql-community-client-plugins = 8.0.24-1.el8 is needed by mysql-community-client-8.0.24-1.el8.x86_64
        mysql-community-libs(x86-64) >= 8.0.11 is needed by mysql-community-client-8.0.24-1.el8.x86_64

[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-libs-8.0.24-1.el8.x86_64.rpm
warning: mysql-community-libs-8.0.24-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        mysql-community-client-plugins = 8.0.24-1.el8 is needed by mysql-community-libs-8.0.24-1.el8.x86_64


[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-client-plugins-8.0.24-1.el8.x86_64.rpm
[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-libs-8.0.24-1.el8.x86_64.rpm
[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-client-8.0.24-1.el8.x86_64.rpm
[root@C84MySQL8 mysql8]# rpm -ivh mysql-community-server-8.0.24-1.el8.x86_64.rpm
warning: mysql-community-server-8.0.24-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.0.24-1.e################################# [100%]
[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.

文件


[root@C84MySQL8 mysql8]# rpm -ql  $(rpm -qa | grep mysql) | grep -e bin -e etc
/usr/bin/mysql
/usr/bin/mysql_config_editor
/usr/bin/mysql_migrate_keyring
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqlimport
/usr/bin/mysqlpump
/usr/bin/mysqlshow
/usr/bin/mysqlslap
/usr/share/man/man1/mysqlbinlog.1.gz
/etc/ld.so.conf.d/mysql-x86_64.conf
/etc/logrotate.d/mysql
/etc/my.cnf
/etc/my.cnf.d
/usr/bin/ibd2sdi
/usr/bin/innochecksum
/usr/bin/lz4_decompress
/usr/bin/my_print_defaults
/usr/bin/myisam_ftdump
/usr/bin/myisamchk
/usr/bin/myisamlog
/usr/bin/myisampack
/usr/bin/mysql_secure_installation
/usr/bin/mysql_ssl_rsa_setup
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_upgrade
/usr/bin/mysqld_pre_systemd
/usr/bin/mysqldumpslow
/usr/bin/perror
/usr/bin/zlib_decompress
/usr/lib64/mysql/mecab/dic/ipadic_euc-jp/char.bin
/usr/lib64/mysql/mecab/dic/ipadic_euc-jp/matrix.bin
/usr/lib64/mysql/mecab/dic/ipadic_sjis/char.bin
/usr/lib64/mysql/mecab/dic/ipadic_sjis/matrix.bin
/usr/lib64/mysql/mecab/dic/ipadic_utf-8/char.bin
/usr/lib64/mysql/mecab/dic/ipadic_utf-8/matrix.bin
/usr/lib64/mysql/mecab/etc
/usr/lib64/mysql/mecab/etc/mecabrc
/usr/sbin/mysqld

启动,初期设置

# MySQL8,追加了一个扩展的端口33060
[root@C84MySQL8 mysql8]# systemctl start mysqld
[root@C84MySQL8 mysql8]# ss -ntlp | grep mysqld
LISTEN 0      70                 *:33060            *:*    users:(("mysqld",pid=14684,fd=22))
LISTEN 0      128                *:3306             *:*    users:(("mysqld",pid=14684,fd=25))


[root@C84MySQL8 mysql8]# grep password /var/log/mysqld.log
2021-12-23T13:43:38.889596Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: a:bgo1LNlYuj


[root@C84MySQL8 mysql8]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@C84MySQL8 mysql8]# mysql -uroot -p'a:bgo1LNlYuj'
mysql: [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 9
Server version: 8.0.24

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
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.# 修改密码后才能执行

mysql> alter user 'root'@'localhost' identified by 'MySQL123!';
Query OK, 0 rows affected (0.03 sec)

mysql> status
--------------
mysql  Ver 8.0.24 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:          9
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.24
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /var/lib/mysql/mysql.sock
Binary data as:         Hexadecimal
Uptime:                 1 min 10 sec

Threads: 2  Questions: 7  Slow queries: 0  Opens: 130  Flush tables: 3  Open tables: 46  Queries per second avg: 0.100
--------------

mysql_secure_installation

# MySQL是下划线
[root@C84MySQL8 mysql8]# rpm -ql $(rpm -qa | grep mysql) | grep secure_ins
/usr/bin/mysql_secure_installation

[root@C84MySQL8 mysql8]# file /usr/bin/mysql_secure_installation
/usr/bin/mysql_secure_installation: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=f152cebc71ab7344b3a7f1572de74d32e74048f4, stripped
# 不是脚本

运行安全安装之前(MySQL8比较严,不给登录)

[root@C84MySQL8 mysql8]# mysql -urrsx
ERROR 1045 (28000): Access denied for user 'rrsx'@'localhost' (using password: NO)
[root@C84MySQL8 mysql8]# mysql -uuser
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO)

[root@C84MySQL8 ~]# mysql -uajflka -p'sfa'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'ajflka'@'localhost' (using password: YES)

[root@C84MySQL8 ~]# mysql -uanonymous
ERROR 1045 (28000): Access denied for user 'anonymous'@'localhost' (using password: NO)
[root@C84MySQL8 ~]# mysql -uanonymous -panonymous
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'anonymous'@'localhost' (using password: YES)

运行安全安装(好像没什么用了,MySQL8里,匿名用户本就不能登录,还是说有其他方式?▲▲)

[root@C84MySQL8 ~]# /usr/bin/mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : B

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

mariadb-secure-installation

程序

[root@c79maria10 ~]# rpm -ql $(rpm -qa | grep MariaDB) | grep bin
/usr/bin/mariadb
/usr/bin/mariadb-access
/usr/bin/mariadb-admin
/usr/bin/mariadb-binlog
/usr/bin/mariadb-check
/usr/bin/mariadb-conv
/usr/bin/mariadb-convert-table-format
/usr/bin/mariadb-dump
/usr/bin/mariadb-dumpslow
/usr/bin/mariadb-embedded
/usr/bin/mariadb-find-rows
/usr/bin/mariadb-hotcopy
/usr/bin/mariadb-import
/usr/bin/mariadb-plugin
/usr/bin/mariadb-secure-installation
/usr/bin/mariadb-setpermission
/usr/bin/mariadb-show
/usr/bin/mariadb-slap
/usr/bin/mariadb-tzinfo-to-sql
/usr/bin/mariadb-waitpid
/usr/bin/msql2mysql
/usr/bin/my_print_defaults
/usr/bin/mysql
/usr/bin/mysql_embedded
/usr/bin/mysql_find_rows
/usr/bin/mysql_plugin
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_waitpid
/usr/bin/mysqlaccess
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqlimport
/usr/bin/mysqlshow
/usr/bin/mysqlslap
/usr/bin/mytop
/usr/bin/replace
/usr/share/man/man1/mariadb-binlog.1.gz
/usr/share/man/man1/mysqlbinlog.1.gz
/usr/bin/aria_chk
/usr/bin/aria_dump_log
/usr/bin/aria_ftdump
/usr/bin/aria_pack
/usr/bin/aria_read_log
/usr/bin/galera_new_cluster
/usr/bin/galera_recovery
/usr/bin/innochecksum
/usr/bin/mariadb-fix-extensions
/usr/bin/mariadb-install-db
/usr/bin/mariadb-service-convert
/usr/bin/mariadb-upgrade
/usr/bin/mariadbd-multi
/usr/bin/mariadbd-safe
/usr/bin/mariadbd-safe-helper
/usr/bin/myisam_ftdump
/usr/bin/myisamchk
/usr/bin/myisamlog
/usr/bin/myisampack
/usr/bin/mysql_fix_extensions
/usr/bin/mysql_install_db
/usr/bin/mysql_upgrade
/usr/bin/mysqld_multi
/usr/bin/mysqld_safe
/usr/bin/mysqld_safe_helper
/usr/bin/perror
/usr/bin/resolve_stack_dump
/usr/bin/resolveip
/usr/bin/wsrep_sst_common
/usr/bin/wsrep_sst_mariabackup
/usr/bin/wsrep_sst_mysqldump
/usr/bin/wsrep_sst_rsync
/usr/bin/wsrep_sst_rsync_wan
/usr/sbin/mariadbd
/usr/sbin/mysqld
/usr/sbin/rcmysql
/usr/share/mysql/binary-configure
/usr/share/mysql/policy/apparmor/usr.sbin.mysqld
/usr/share/mysql/policy/apparmor/usr.sbin.mysqld.local

运行安全程序,设置root密码,root的远程登录,删除anonymous账户和test数据库等

/usr/bin/mariadb-secure-installation

[root@c79maria10 ~]# file /usr/bin/mariadb-secure-installation
/usr/bin/mariadb-secure-installation: POSIX shell script, ASCII text executable

运行脚本之前

# 任意名的用户都可以免密码本地登录
[root@c79maria10 ~]# mysql -uyyy
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.6.5-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> exit
Bye
[root@c79maria10 ~]# mysql -uaaaa
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.6.5-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>


MariaDB [(none)]> show databases;	# 可以查询数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.002 sec)

MariaDB [(none)]> select user,host from mysql.user;	# MariaDB 10需要明确的权限来查询用户
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'

MariaDB [(none)]> use test;
Database changed
MariaDB [test]> show tables;
Empty set (0.000 sec)


MariaDB [test]> create database test1;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'test1'

MariaDB [test]> status
--------------
mysql  Ver 15.1 Distrib 10.6.5-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:          6
Current database:       test
Current user:           aaaa@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.6.5-MariaDB MariaDB Server
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8mb3
Conn.  characterset:    utf8mb3
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 9 min 27 sec

Threads: 1  Questions: 24  Slow queries: 0  Opens: 17  Open tables: 10  Queries per second avg: 0.042
--------------

运行安全脚本

# MariaDB123!


[root@c79maria10 ~]# /usr/bin/mariadb-secure-installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n	# 切换socket认证??
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]	# 删除匿名
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n	# root的远程登录
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y	# 重载权限设置
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!



[root@c79maria10 ~]# mysql -uroot -p''MariaDB123!
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.6.5-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------+
| mariadb.sys | localhost |
| mysql       | localhost |
| root        | localhost |
+-------------+-----------+
3 rows in set (0.002 sec)


二进制安装(免安装二进制)

CentOS8安装MySQL8.0(二进制)

通用二进制安装教程

# https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
# 大致流程
  $> groupadd mysql
  $> useradd -r -g mysql -s /bin/false mysql
  $> cd /usr/local
  $> tar xvf /path/to/mysql-VERSION-OS.tar.xz
  $> ln -s full-path-to-mysql-VERSION-OS mysql
  $> cd mysql
  $> mkdir mysql-files
  $> chown mysql:mysql mysql-files
  $> chmod 750 mysql-files
  $> bin/mysqld --initialize --user=mysql
  $> bin/mysql_ssl_rsa_setup
  $> bin/mysqld_safe --user=mysql &
  # Next command is optional
  $> cp support-files/mysql.server /etc/init.d/mysql.server


准备一个干净的系统(or完全卸载MySQL和MariaDB)


[root@C84MySQL8a ~]# rpm -qa  | grep -i -e mysql -e mariadb
[root@C84MySQL8a ~]# echo $?
1

[root@C84MySQL8a ~]# find / -name my.cnf
[root@C84MySQL8a ~]# echo $?
0

安装依赖包

[root@C84MySQL8a ~]# dnf -y install libaio ncurses-compat-libs

创建用户和组

[root@C84MySQL8a ~]# groupadd -r -g 360 mysql
[root@C84MySQL8a ~]# useradd -r -g 360 -u 360 -d /data/mysql mysql
[root@C84MySQL8a ~]# id mysql
uid=360(mysql) gid=360(mysql) groups=360(mysql)

创建数据目录

[root@C84MySQL8a ~]# mkdir /data/mysql
[root@C84MySQL8a ~]# chown mysql:mysql /data/mysql/
[root@C84MySQL8a ~]# ll -d /data/mysql/
drwxr-xr-x. 2 mysql mysql 6 Dec 25 10:23 /data/mysql/

下载免安装包

# URL
# https://dev.mysql.com/downloads/mysql/
# 需选择
# Linux - Generic
# 才能显示出xxxxx.tar.gz包(这个要1G多,真大!!!比rpm大了一倍)xz来的

Compressed TAR Archive
(mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz)
MD5: 0bdd171cb8464ba32f65f7bf58bc9533

# 换一个
# https://downloads.mysql.com/archives/community/
# 

Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive
(mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz)
MD5: c1b7e64241866ed68f7c637c99fe39a4



[root@C84MySQL8a ~]# mkdir mysql8.bin
[root@C84MySQL8a ~]# cd mysql8.bin/
[root@C84MySQL8a mysql8.bin]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
--2021-12-25 10:36:28--  https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
Resolving downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz [following]
--2021-12-25 10:36:29--  https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 104.93.8.235
Connecting to cdn.mysql.com (cdn.mysql.com)|104.93.8.235|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 603019898 (575M) [application/x-tar-gz]
Saving to: ‘mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz’

0.11-linux-glibc2.12-x86_64   7%[==>                                         ]  43.07M  10.3MB/s    eta 57s


[root@C84MySQL8a mysql8.bin]# ll -h
total 576M
-rw-r--r--. 1 root root 576M Apr  8  2018 mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz


[root@C84MySQL8a mysql8.bin]# md5sum mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
c1b7e64241866ed68f7c637c99fe39a4  mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz

开始部署MySQL8

# 解压
[root@C84MySQL8a mysql8.bin]# tar xf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@C84MySQL8a mysql8.bin]# cd /usr/local
[root@C84MySQL8a local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql-8.0.11-linux-glibc2.12-x86_64  sbin  share  src

# 配置软连接
[root@C84MySQL8a local]# ln -sv mysql-8.0.11-linux-glibc2.12-x86_64 mysql
'mysql' -> 'mysql-8.0.11-linux-glibc2.12-x86_64'
[root@C84MySQL8a local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  mysql-8.0.11-linux-glibc2.12-x86_64  sbin  share  src

# 修改权限

[root@C84MySQL8a local]# ll mysql/
total 308
drwxr-xr-x.  2 root root    4096 Dec 25 10:39 bin
drwxr-xr-x.  2 root root      55 Dec 25 10:39 docs
drwxr-xr-x.  3 root root     266 Dec 25 10:39 include
drwxr-xr-x.  5 root root     272 Dec 25 10:39 lib
-rw-r--r--.  1 7161 31415 301518 Apr  8  2018 LICENSE
drwxr-xr-x.  4 root root      30 Dec 25 10:39 man
-rw-r--r--.  1 7161 31415    687 Apr  8  2018 README
drwxr-xr-x. 28 root root    4096 Dec 25 10:39 share
drwxr-xr-x.  2 root root      90 Dec 25 10:39 support-files

[root@C84MySQL8a local]# chown -R root:root /usr/local/mysql/


# 配置文件(没有提供模板cnf。。。)
[root@C84MySQL8a local]# cd /usr/local/mysql

[root@C84MySQL8a mysql]# cat /etc/my.cnf
[mysqld]
datadir = /data/mysql

# 初始化
[root@C84MySQL8a mysql]# bin/mysqld --initialize --user=mysql --datadir=/data/mysql
2021-12-25T01:49:41.304812Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.11-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 9742
2021-12-25T01:49:43.918108Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Y&Ai;Lfpy0Jd
2021-12-25T01:49:45.515989Z 0 [System] [MY-013170] [Server] /usr/local/mysql-8.0.11-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.11) initializing of server has completed
[root@C84MySQL8a mysql]#


[root@C84MySQL8a mysql]# bin/mysql_ssl_rsa_setup
[root@C84MySQL8a mysql]# echo $?
0
[root@C84MySQL8a mysql]#

# 启动(为何是启动mysql_safe▲▲第一次的原因?)
[root@C84MySQL8a mysql]# bin/mysqld_safe --user=mysql &
[1] 9791
[root@C84MySQL8a mysql]# Logging to '/data/mysql/C84MySQL8a.err'.
2021-12-25T01:50:55.183980Z mysqld_safe Starting mysqld daemon with databases from /data/mysql

# 修改密码

[root@C84MySQL8a mysql]# bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@C84MySQL8a mysql]# bin/mysql -uroot -p'Y&Ai;Lfpy0Jd'
Your MySQL connection id is 9
Server version: 8.0.11

mysql> status
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


mysql> alter user 'root'@'localhost' identified by 'MySQL123!';
Query OK, 0 rows affected (0.10 sec)

mysql> status
--------------
bin/mysql  Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

Connection id:          9
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.11
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /tmp/mysql.sock
Uptime:                 4 min 42 sec

Threads: 2  Questions: 11  Slow queries: 0  Opens: 123  Flush tables: 2  Open tables: 99  Queries per second avg: 0.039
--------------

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

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


配置客户端自动登录


[root@C84MySQL8a mysql]# cat ~/.my.cnf
[mysql]
user=root
password=MySQL123!
[root@C84MySQL8a mysql]# bin/mysqladmin shutdown
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

设置启动脚本(init)

[root@C84MySQL8a mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
[root@C84MySQL8a mysql]# ls /etc/init.d/
functions  mysql.server  README

[root@C84MySQL8a mysql]# service mysql.server status
 SUCCESS! MySQL running (9888)


[root@C84MySQL8a mysql]# kill -9 9888
[root@C84MySQL8a mysql]# bin/mysqld_safe: line 199:  9888 Killed                  env MYSQLD_PARENT_PID=9791 nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=C84MySQL8a.err --pid-file=C84MySQL8a.pid < /dev/null > /dev/null 2>&1
2021-12-25T02:00:36.718453Z mysqld_safe Number of processes running now: 0
2021-12-25T02:00:36.723661Z mysqld_safe mysqld restarted


[root@C84MySQL8a mysql]# service mysql.server status
 SUCCESS! MySQL running (10007)

# 无法kill???▲▲自我保护机制??

[root@C84MySQL8a mysql]# bin/mysqladmin shutdown -uroot -p'MySQL123!'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@C84MySQL8a mysql]# 2021-12-25T02:05:52.209461Z mysqld_safe mysqld from pid file /data/mysql/C84MySQL8a.pid ended

[1]+  Done                    bin/mysqld_safe --user=mysql
[root@C84MySQL8a mysql]# ps -ef | grep mysql
root       10222     990  0 11:06 pts/0    00:00:00 grep --color=auto mysql


[root@C84MySQL8a mysql]# service mysql.server status
 ERROR! MySQL is not running


[root@C84MySQL8a mysql]# service mysql.server start
Starting MySQL. SUCCESS!
[root@C84MySQL8a mysql]# ps -ef | grep mysql
root       10265       1  0 11:07 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/C84MySQL8a.pid
mysql      10377   10265  7 11:07 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=C84MySQL8a.err --pid-file=/data/mysql/C84MySQL8a.pid
root       10420     990  0 11:08 pts/0    00:00:00 grep --color=auto mysql
[root@C84MySQL8a mysql]# bin/mysql -uroot -p'MySQL123!'
mysql: [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 8


[root@C84MySQL8a mysql]# service mysql.server stop
Shutting down MySQL.. SUCCESS!
[root@C84MySQL8a mysql]# service mysql.server status
 ERROR! MySQL is not running

设置启动脚本(systemd)▲参考其他安装方法生成的mysql.service文件


[root@C84MySQL8a ~]# cat /etc/systemd/system/mysqld8.service
[Unit]
Description=MySQL Server 8 GPL
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
# ExecStartPre=/usr/bin/mysqld_pre_systemd
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
# EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false


[root@C84MySQL8a ~]# systemctl daemon-reload
[root@C84MySQL8a ~]# systemctl status mysqld8
● mysqld8.service - MySQL Server 8 GPL
   Loaded: loaded (/etc/systemd/system/mysqld8.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html



[root@C84MySQL8a ~]# systemctl start mysqld8
[root@C84MySQL8a ~]# systemctl status mysqld8
● mysqld8.service - MySQL Server 8 GPL
   Loaded: loaded (/etc/systemd/system/mysqld8.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-12-25 11:19:33 JST; 5s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 10605 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 37 (limit: 5979)
   Memory: 363.1M
   CGroup: /system.slice/mysqld8.service
           └─10605 /usr/local/mysql/bin/mysqld

Dec 25 11:19:32 C84MySQL8a systemd[1]: Starting MySQL Server 8 GPL...
Dec 25 11:19:33 C84MySQL8a mysqld[10605]: 2021-12-25T02:19:33.117257Z 0 [System] [MY-010116] [Server] /usr/loca>
Dec 25 11:19:33 C84MySQL8a mysqld[10605]: 2021-12-25T02:19:33.486045Z 0 [Warning] [MY-010068] [Server] CA certi>
Dec 25 11:19:33 C84MySQL8a mysqld[10605]: 2021-12-25T02:19:33.506638Z 0 [System] [MY-010931] [Server] /usr/loca>
Dec 25 11:19:33 C84MySQL8a systemd[1]: Started MySQL Server 8 GPL.


[root@C84MySQL8a ~]# mysql -uroot -p'MySQL123!'
mysql> status
--------------
mysql  Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)

Connection id:          8
Current user:           root@localhost
Connection:             Localhost via UNIX socket


# init的也可以看到,是因为用来一样的配置文件?/etc/my.cnf▲
[root@C84MySQL8a ~]# service mysql.server status
 SUCCESS! MySQL running (10605)

# 命令的参数变少了
[root@C84MySQL8a ~]# ps -ef | grep mysqld
mysql      10605       1  0 11:19 ?        00:00:00 /usr/local/mysql/bin/mysqld
root       10666     990  0 11:21 pts/0    00:00:00 grep --color=auto mysqld

# 都是控制一个进程来的
[root@C84MySQL8a ~]# service mysql.server stop
Shutting down MySQL.. SUCCESS!
[root@C84MySQL8a ~]# systemctl status mysqld8
● mysqld8.service - MySQL Server 8 GPL
   Loaded: loaded (/etc/systemd/system/mysqld8.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

配置环境变量

[root@C84MySQL8a ~]# tail -1 .bash_profile
export PATH=$PATH:/usr/local/mysql/bin

[root@C84MySQL8a ~]# source .bash_profile

# 或者配置全局

[root@C84MySQL8a ~]# echo 'PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysqld.sh
[root@C84MySQL8a ~]# cat /etc/profile.d/mysqld.sh
PATH=$PATH:/usr/local/mysql/bin

[root@C84MySQL8a ~]# source /etc/profile.d/mysqld.sh


mysql_secure_installation进行初期安全设置

mysql_secure_installation

源码安装

源码编译MySQL8

安装依赖包


[root@C84MySQL8SRC ~]# yum -y install epel-release

[root@C84MySQL8SRC ~]# dnf -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel wget libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper tar

Error: Unable to find a match: bison-devel libarchive-devel ncurses-del
# 没有?暂时忽略

[root@C84MySQL8SRC ~]# dnf -y install gcc gcc-c++ cmake bison zlib-devel libcurl-devel wget boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper tar

创建用户和数据目录


[root@C84MySQL8SRC ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@C84MySQL8SRC ~]# id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)

[root@C84MySQL8SRC ~]# mkdir /data/mysql
[root@C84MySQL8SRC ~]# chown mysql:mysql /data/mysql/
[root@C84MySQL8SRC ~]# ll -d /data/mysql/
drwxr-xr-x. 2 mysql mysql 6 Dec 25 12:27 /data/mysql/

[root@C84MySQL8SRC ~]# mkdir /usr/local/mysql

[root@C84MySQL8SRC ~]# mkdir mysql8scr
[root@C84MySQL8SRC ~]# cd mysql8scr/

下载源码

# https://downloads.mysql.com/archives/community/

Generic Linux (Architecture Independent), Compressed TAR Archive
(mysql-8.0.11.tar.gz)
MD5: 38d5a5c1a1eeed1129fec3a999aa5efd

[root@C84MySQL8SRC mysql8scr]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.11.tar.gz
--2021-12-25 12:29:05--  https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.11.tar.gz
Resolving downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.11.tar.gz [following]
--2021-12-25 12:29:06--  https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.11.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 104.93.8.235
Connecting to cdn.mysql.com (cdn.mysql.com)|104.93.8.235|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 79361578 (76M) [application/x-tar-gz]
Saving to: ‘mysql-8.0.11.tar.gz’

mysql-8.0.11.tar.gz          57%[========================>                   ]  43.66M  10.2MB/s    eta 5s


[root@C84MySQL8SRC mysql8scr]# md5sum mysql-8.0.11.tar.gz
38d5a5c1a1eeed1129fec3a999aa5efd  mysql-8.0.11.tar.gz

[root@C84MySQL8SRC mysql8scr]# tar xzf mysql-8.0.11.tar.gz
[root@C84MySQL8SRC mysql8scr]# ls
mysql-8.0.11  mysql-8.

相关文章