1、CentOS7 RPM方式安装MySQL5.7?
离线安装:上传已经从官网下载好的rpm包到虚拟机
[root@localhost ~]# ls -l mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 root root 545863680 Dec 10 20:28 mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
?解压:
[root@localhost ~]# tar xf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
[root@localhost ~]# ls -l mysql-
mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.36-1.el7.x86_64.rpm
mysql-community-common-5.7.36-1.el7.x86_64.rpm
mysql-community-devel-5.7.36-1.el7.x86_64.rpm
mysql-community-embedded-5.7.36-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.36-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.36-1.el7.x86_64.rpm
mysql-community-libs-5.7.36-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.36-1.el7.x86_64.rpm
mysql-community-server-5.7.36-1.el7.x86_64.rpm
mysql-community-test-5.7.36-1.el7.x86_64.rpm
?安装:
[root@localhost ~]# yum remove mariadb-libs //移除mariadb的libs
[root@localhost ~]# rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm mysql-community-common-5.7.36-1.el7.x86_64.rpm mysql-community-libs-5.7.36-1.el7.x86_64.rpm mysql-community-server-5.7.36-1.el7.x86_64.rpm
?启动服务:
[root@localhost ~]# systemctl enable --now mysqld //设置为开机自启并立即启动
登录:
[root@localhost ~]# P=`awk '/temporary password/ {print $NF}' /var/log/mysqld.log`
[root@localhost ~]# mysql -uroot -p$P
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 4
Server version: 5.7.36
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.
2、CentOS7 通用二进制方式安装MySQL5.7?
上传已经从官网下载好的二进制包到虚拟机:
[root@localhost ~]# ls
anaconda-ks.cfg mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
新建用户以安全的方式运行进程:
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql
?解压:
[root@localhost ~]# tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /usr/local
?设置软链接:
[root@localhost ~]# ln -sv /usr/local/mysql-5.7.36-linux-glibc2.12-x86_64/ /usr/local/mysql
"/usr/local/mysql" -> "/usr/local/mysql-5.7.36-linux-glibc2.12-x86_64/"
?初始化:
[root@localhost ~]# mkdir -p /data/mysql
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[root@localhost ~]# ll /data/mysql
总用量 110660
-rw-r-----. 1 mysql mysql 56 12月 10 21:42 auto.cnf
-rw-------. 1 mysql mysql 1680 12月 10 21:42 ca-key.pem
-rw-r--r--. 1 mysql mysql 1112 12月 10 21:42 ca.pem
-rw-r--r--. 1 mysql mysql 1112 12月 10 21:42 client-cert.pem
-rw-------. 1 mysql mysql 1680 12月 10 21:42 client-key.pem
-rw-r-----. 1 mysql mysql 436 12月 10 21:42 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 12月 10 21:42 ibdata1
-rw-r-----. 1 mysql mysql 50331648 12月 10 21:42 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 12月 10 21:42 ib_logfile1
drwxr-x---. 2 mysql mysql 4096 12月 10 21:42 mysql
drwxr-x---. 2 mysql mysql 8192 12月 10 21:42 performance_schema
-rw-------. 1 mysql mysql 1676 12月 10 21:42 private_key.pem
-rw-r--r--. 1 mysql mysql 452 12月 10 21:42 public_key.pem
-rw-r--r--. 1 mysql mysql 1112 12月 10 21:42 server-cert.pem
-rw-------. 1 mysql mysql 1676 12月 10 21:42 server-key.pem
drwxr-x---. 2 mysql mysql 8192 12月 10 21:42 sys
?为MySQL提供一个服务脚本:
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
?修改:
[root@localhost ~]# vi /etc/init.d/mysql.server /指定MySQL的位置
basedir=/usr/local/mysql
datadir=/data/mysql
修改:
[root@localhost ~]# vi /etc/my.cnf /指定MySQL的相关位置
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/data/mysql/mysqld.pid
?启动MySQL
[root@localhost ~]# chkconfig --add mysql.server /添加为系统服务
[root@localhost ~]# chkconfig mysql.server on /开机自启动
[root@localhost ~]# systemctl start mysql.server
将mysql的bin目录加入环境变量
[root@localhost ~]# cd /etc/profile.d/
[root@localhost profile.d]# vi mysql.sh
添加如下:
export PATH=$PATH:/usr/local/mysql/bin
登录:
[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p'9#G*edizfc*)'
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 20
Server version: 5.7.36
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.
3、简述MySQL体系结构。?
MySQL 由连接池、SQL 接口、解析器、优化器、缓存、存储引擎等组成,可以分为三层,即 MySQL Server 层、存储引擎层和文件系统层。MySQL Server 层又包括连接层和 SQL 层
1. 连接层
应用程序通过接口(如 ODBC、JDBC)来连接 MySQL,最先连接处理的是连接层。连接层包括通信协议、线程处理、用户名密码认证 3 部分。
2. SQL层
SQL 层是 MySQL 的核心,MySQL 的核心服务都是在这层实现的。主要包含权限判断、查询缓存、解析器、预处理、查询优化器、缓存和执行计划。
3. 存储引擎层
Pluggable Storage Engines 属于存储引擎层。存储引擎层是 MySQL 数据库区别于其他数据库最核心的一点,也是 MySQL 最具特色的一个地方。主要负责 MySQL 中数据的存储和提取。 因为在关系数据库中,数据的存储是以表的形式存储的,所以存储引擎也可以称为表类型(即存储和操作此表的类型)。
4. 文件系统层
文件系统层主要是将数据库的数据存储在操作系统的文件系统之上,并完成与存储引擎的交互。
4、使用mysql客户端登录服务器,重置root密码
登录数据库:
[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p'9#G*edizfc*)'
mysql> alter user root@localhost identified by 'MySQL@123';
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
[root@localhost ~]# mysql -uroot -p'MySQL@123'
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 21
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.
|